<commit_before>module Actions
  module Repository
    define_action :index do
      str = self.class.to_s.sub /Controller$/, ''
      var =  "@#{str.underscore.pluralize}"
      model = str.singularize.camelize.constantize

      instance_variable_set var, model.all

      respond_to do |format|
        format.html
        format.xml { render :xml => instance_variable_get(var) }
      end
    end

    define_action :new do
      str = self.class.to_s.sub /Controller$/, ''
      var =  "@#{str.underscore.singularize}"
      model = str.singularize.camelize.constantize

      instance_variable_set var, model.new
      
      respond_to do |format|
        format.html
        format.xml { render :xml => instance_variable_get(var) }
      end
    end

    define_action :edit do
      str = self.class.to_s.sub /Controller$/, ''
      var =  "@#{str.underscore.singularize}"
      model = str.singularize.camelize.constantize

      instance_variable_set var, model.find(params[:id])
    end

    define_action :show do
      str = self.class.to_s.sub /Controller$/, ''
      var =  "@#{str.underscore.singularize}"
      model = str.singularize.camelize.constantize

      instance_variable_set var, model.find(params[:id])
      respond_to do |format|
        format.html
        format.xml { render :xml => instance_variable_get(var) }
      end
    end

    define_action :create do
      str = self.class.to_s.sub /Controller$/, ''
      var =  "@#{str.underscore.singularize}"
      model = str.singularize.camelize.constantize

      item = model.new(params[str.underscore.singularize])
      instance_variable_set(var, item)

      respond_to do |format|
        if item.save
          flash[:notice] = str.singularize.camelize + ' was successfully created.'
          format.html { redirect_to(item) }
          format.xml  { render :xml => item, :status => :created, :location => item }
        else
          format.html { render :action => "new" }
          format.xml  { render :xml => item.errors, :status => :unprocessable_entity }
        end
      end
    end

    define_action :destroy do
      str = self.class.to_s.sub /Controller$/, ''
      var =  "@#{str.underscore.singularize}"
      model = str.singularize.camelize.constantize

      item = model.find(params[:id])
      item.destroy

      respond_to do |format|
        format.html { redirect_to(eval("#{str.underscore.pluralize}_url")) }
        format.xml  { head :ok }
      end
    end

    define_action :update do
      str = self.class.to_s.sub /Controller$/, ''
      var =  "@#{str.underscore.singularize}"
      model = str.singularize.camelize.constantize

      instance_variable_set var, (item = model.find(params[:id]))

      respond_to do |format|
        if item.update_attributes(params[str.underscore.singularize])
          flash[:notice] = str.camelize + ' was successfully updated.'
          format.html { redirect_to(item) }
          format.xml  { head :ok }
        else
          format.html { render :action => "edit" }
          format.xml  { render :xml => item.errors, :status => :unprocessable_entity }
        end
      end
    end<commit_msg>Update action fix<commit_after>module Actions
  module Repository
    define_action :index do
      str = self.class.to_s.sub /Controller$/, ''
      var =  "@#{str.underscore.pluralize}"
      model = str.singularize.camelize.constantize

      instance_variable_set var, model.all

      respond_to do |format|
        format.html
        format.xml { render :xml => instance_variable_get(var) }
      end
    end

    define_action :new do
      str = self.class.to_s.sub /Controller$/, ''
      var =  "@#{str.underscore.singularize}"
      model = str.singularize.camelize.constantize

      instance_variable_set var, model.new
      
      respond_to do |format|
        format.html
        format.xml { render :xml => instance_variable_get(var) }
      end
    end

    define_action :edit do
      str = self.class.to_s.sub /Controller$/, ''
      var =  "@#{str.underscore.singularize}"
      model = str.singularize.camelize.constantize

      instance_variable_set var, model.find(params[:id])
    end

    define_action :show do
      str = self.class.to_s.sub /Controller$/, ''
      var =  "@#{str.underscore.singularize}"
      model = str.singularize.camelize.constantize

      instance_variable_set var, model.find(params[:id])
      respond_to do |format|
        format.html
        format.xml { render :xml => instance_variable_get(var) }
      end
    end

    define_action :create do
      str = self.class.to_s.sub /Controller$/, ''
      var =  "@#{str.underscore.singularize}"
      model = str.singularize.camelize.constantize

      item = model.new(params[str.underscore.singularize])
      instance_variable_set(var, item)

      respond_to do |format|
        if item.save
          flash[:notice] = str.singularize.camelize + ' was successfully created.'
          format.html { redirect_to(item) }
          format.xml  { render :xml => item, :status => :created, :location => item }
        else
          format.html { render :action => "new" }
          format.xml  { render :xml => item.errors, :status => :unprocessable_entity }
        end
      end
    end

    define_action :destroy do
      str = self.class.to_s.sub /Controller$/, ''
      var =  "@#{str.underscore.singularize}"
      model = str.singularize.camelize.constantize

      item = model.find(params[:id])
      item.destroy

      respond_to do |format|
        format.html { redirect_to(eval("#{str.underscore.pluralize}_url")) }
        format.xml  { head :ok }
      end
    end

    define_action :update do
      str = self.class.to_s.sub /Controller$/, ''
      var =  "@#{str.underscore.singularize}"
      model = str.singularize.camelize.constantize

      instance_variable_set var, (item = model.find(params[:id]))

      respond_to do |format|
        if item.update_attributes(params[str.underscore.singularize])
          flash[:notice] = str.singularize.camelize + ' was successfully updated.'
          format.html { redirect_to(item) }
          format.xml  { head :ok }
        else
          format.html { render :action => "edit" }
          format.xml  { render :xml => item.errors, :status => :unprocessable_entity }
        end
      end
    end
{'fraction_non_alphanumeric': 0.11719242902208202, 'fraction_numerical': 0.0, 'mean_word_length': 2.358580508474576, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 28}, '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': '2741171', 'n_tokens_mistral': 1997, 'n_tokens_neox': 1935, 'n_words': 403}