<commit_before>require 'rails3_backport/mime_responds';

module ActionBuilder


  module ClassMethods


    def has_actions_for(mod, *args)
      options = args.extract_options!      
      actions = get_actions(options)
      module_name = mod.name
      collection_name = module_name.tableize
      instance_name = collection_name.singularize

      define_method "index" do
        collection = mod.find(:all, eval_params(options[:find]))
        instance_variable_set("@#{collection_name}", collection)
        instance_variable_set("@#{instance_name}", mod.new(eval_params(options[:new]))) # if (resource_type == :simple_record)
        respond_with(collection)
      end if actions.member? :index
      
      define_method "show" do
        record = mod.find(params[:id])
        instance_variable_set("@#{instance_name}", record)
        respond_with(record)
      end if actions.member? :show
    
      define_method "new" do
        record = mod.new(eval_params(options[:new]))
        instance_variable_set("@#{instance_name}", record)
        respond_with(record)
      end if actions.member? :new

      define_method "edit" do
        record = mod.find(params[:id])
        instance_variable_set("@#{instance_name}", record)
      end if actions.member? :edit
    
      define_method "create" do
        record = mod.new(params[instance_name])
        instance_variable_set("@#{instance_name}",record)
        record.save
        respond_with(record)
      end if actions.member? :create

      define_method "update" do
        record = mod.find(params[:id])
        instance_variable_set("@#{instance_name}",record)
        record.update_attributes(params[instance_name])
        respond_with(record)
      end if actions.member? :update

      define_method "destroy" do
        record = mod.find(params[:id])
        instance_variable_set("@#{instance_name}",record)
        record.destroy
        respond_with(record)
      end if actions.member? :destroy
    end
    
    
  private


    def get_actions(options={})
      only = options[:only]
      except = options[:except]
      return only if only
      return (standard_actions - except) if except
      return standard_actions
    end


    def standard_actions
      [:index, :show, :new, :create, :edit, :update, :destroy]
    end


  end<commit_msg>modified action_builder<commit_after>require 'rails3_backport/mime_responds';

module ActionBuilder


  module ClassMethods


    def has_actions_for(model, *args)
      options = args.extract_options!
      actions = get_actions(options)
      collection_name = model.name.tableize
      instance_name = collection_name.singularize

      define_method "index" do
        collection = model.find(:all, eval_params(options[:find]))
        instance_variable_set("@#{collection_name}", collection)
        instance_variable_set("@#{instance_name}", model.new(eval_params(options[:new]))) # if (resource_type == :simple_record)
        respond_with(collection)
      end if actions.member? :index
      
      define_method "show" do
        record = model.find(params[:id])
        instance_variable_set("@#{instance_name}", record)
        respond_with(record)
      end if actions.member? :show
    
      define_method "new" do
        record = model.new(eval_params(options[:new]))
        instance_variable_set("@#{instance_name}", record)
        respond_with(record)
      end if actions.member? :new

      define_method "edit" do
        record = model.find(params[:id])
        instance_variable_set("@#{instance_name}", record)
      end if actions.member? :edit
    
      define_method "create" do
        record = model.new(params[instance_name])
        instance_variable_set("@#{instance_name}",record)
        record.save
        respond_with(record)
      end if actions.member? :create

      define_method "update" do
        record = model.find(params[:id])
        instance_variable_set("@#{instance_name}",record)
        record.update_attributes(params[instance_name])
        respond_with(record)
      end if actions.member? :update

      define_method "destroy" do
        record = model.find(params[:id])
        instance_variable_set("@#{instance_name}",record)
        record.destroy
        respond_with(record)
      end if actions.member? :destroy
    end
    
    
  private


    def get_actions(options={})
      only = options[:only]
      except = options[:except]
      return only if only
      return (standard_actions - except) if except
      return standard_actions
    end


    def standard_actions
      [:index, :show, :new, :create, :edit, :update, :destroy]
    end


  end
{'fraction_non_alphanumeric': 0.10636012032660078, 'fraction_numerical': 0.0004297378599054577, 'mean_word_length': 2.928270042194093, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5733251', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1319, 'n_words': 276}