<commit_before>module SummerResidents
  class ResidentsController < SummerResidentsController
    skip_before_filter :require_administrator_priveleges, only: [:edit, :update]
    before_filter :require_administrator_priveleges_if_different_user, only: [:edit, :update]

    # GET /residents/1/edit
    def edit
      @resident = Resident.find(params[:id])
      @type = params[:type]
      respond_to do |format|
        format.js { render action: params[:cancel] ? :show : :edit }
      end
    end
  
    # PUT /residents/1
    # PUT /residents/1.json
    def update
      @resident = Resident.find(params[:id])
      [:first_name, :last_name, :cell].each { |f|
        @resident.__send__ "#{f}=", params[f]
      }
      @resident.user.email = params[:email]
      @type = params[:type]

      respond_to do |format|
        format.js { render action: (@resident.save ? :show : :errors) }
      end
    end
  
    # DELETE /residents/1
    # DELETE /residents/1.json
    def destroy
      Resident.find(params[:id]).destroy
  
      respond_to do |format|
        format.js { render nothing: true }
      end
    end
  end
end
<commit_msg>refactored residents_controller in preparation for #11<commit_after>module SummerResidents
  class ResidentsController < SummerResidentsController
    skip_before_filter :require_administrator_priveleges, only: [:edit, :update]
    before_filter :require_administrator_priveleges_if_different_user, only: [:edit, :update]

    def edit
      @resident = Resident.find(params[:id])
      set_type
      edit_but_show_if_cancelled
    end
  
    # PUT /residents/1
    # PUT /residents/1.json
    def update
      @resident = Resident.find(params[:id])
      assign_resident_attributes
      @resident.user.email = params[:email]
      set_type
      show_unless_errors @resident.save
    end
  
    # DELETE /residents/1
    # DELETE /residents/1.json
    def destroy
      Resident.find(params[:id]).destroy
  
      respond_to do |format|
        format.js { render nothing: true }
      end
    end
private
    def set_type
      @type = params[:type]
    end

    def assign_resident_attributes
      [:first_name, :last_name, :cell].each { |f|
        @resident.__send__ "#{f}=", params[f]
      }
    end

    def edit_but_show_if_cancelled
      respond_to do |format|
        format.js { render action: params[:cancel] ? :show : :edit }
      end
    end

    def show_unless_errors if_save
      respond_to do |format|
        format.js { render action: (if_save ? :show : :errors) }
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.1014832162373146, 'fraction_numerical': 0.00429352068696331, 'mean_word_length': 2.677187948350072, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3518583', 'n_tokens_mistral': 844, 'n_tokens_neox': 820, 'n_words': 185}