<commit_before>class EmployeesController < Base::HyaccController
  view_attribute :title => '従業員'
  view_attribute :branches, :except=>[:index, :destroy]

  helper_method :finder

  def index
    @employees = finder.list
  end

  def add_employee_history
    @employee_history = EmployeeHistory.new
  end

  def add_branch
    @be = BranchEmployee.new
    render :partial => 'branch_employee_fields', :locals => {:be => @be, :index => params[:index]}
  end

  def edit
    @e = Employee.find(params[:id])
  end
  
  def show
    @e = Employee.find(params[:id])
  end

  def update
    @e = Employee.find(params[:id])

    begin
      @e.transaction do
        @e.attributes = employee_params
        @e.save!
      end

      flash[:notice] = '従業員を更新しました。'
      render 'common/reload'

    rescue => e
      handle(e)
      render :action => 'edit'
    end
  end

  def destroy
    @employee = Employee.find(params[:id])
    @employee.destroy_logically!

    # 削除したユーザがログインユーザ自身の場合は、ログアウト
    if current_user.employee.id == @employee.id
      reset_session
      redirect_to root_path
    else
      flash[:notice] = '従業員を削除しました。'
      redirect_to :action => :index
    end
  end

  private

  def employee_params
    employee_attributes = [
      :company_id, :first_name, :last_name, :employment_date,
      :zip_code, :address, :sex, :business_office_id, :birth
    ]
    employee_histories_attributes = [:id, :_destroy, :num_of_dependent, :start_date]
    branch_employees_attributes = [:id, :_destroy, :branch_id, :cost_ratio, :default_branch]

    params.require(:employee).permit(
      employee_attributes,
      :employee_histories_attributes => employee_histories_attributes,
      :branch_employees_attributes => branch_employees_attributes)
  end

  def finder
    @finder ||= EmployeeFinder.new(params[:finder])
    @finder.page = params[:page]
    @finder.per_page = current_user.slips_per_page
    @finder
  end

end
<commit_msg>refactor<commit_after>class EmployeesController < Base::HyaccController
  view_attribute :title => '従業員'
  view_attribute :branches, :except => [:index, :destroy]

  helper_method :finder

  def index
    @employees = finder.list
  end

  def add_employee_history
    @employee_history = EmployeeHistory.new
  end

  def add_branch
    @be = BranchEmployee.new
    render :partial => 'branch_employee_fields', :locals => {:be => @be, :index => params[:index]}
  end

  def edit
    @e = Employee.find(params[:id])
  end
  
  def show
    @e = Employee.find(params[:id])
  end

  def update
    @e = Employee.find(params[:id])

    begin
      @e.transaction do
        @e.attributes = employee_params
        @e.save!
      end

      flash[:notice] = '従業員を更新しました。'
      render 'common/reload'

    rescue => e
      handle(e)
      render :action => 'edit'
    end
  end

  def destroy
    @employee = Employee.find(params[:id])
    @employee.destroy_logically!

    # 削除したユーザがログインユーザ自身の場合は、ログアウト
    if current_user.employee.id == @employee.id
      reset_session
      redirect_to root_path
    else
      flash[:notice] = '従業員を削除しました。'
      redirect_to :action => :index
    end
  end

  private

  def employee_params
    employee_attributes = [
      :company_id, :first_name, :last_name, :employment_date,
      :zip_code, :address, :sex, :business_office_id, :birth
    ]
    employee_histories_attributes = [:id, :_destroy, :num_of_dependent, :start_date]
    branch_employees_attributes = [:id, :_destroy, :branch_id, :cost_ratio, :default_branch]

    params.require(:employee).permit(
      employee_attributes,
      :employee_histories_attributes => employee_histories_attributes,
      :branch_employees_attributes => branch_employees_attributes)
  end

  def finder
    @finder ||= EmployeeFinder.new(params[:finder])
    @finder.page = params[:page]
    @finder.per_page = current_user.slips_per_page
    @finder
  end

end

{'fraction_non_alphanumeric': 0.10456226880394574, 'fraction_numerical': 0.0, 'mean_word_length': 2.787114845938375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '6187393', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1313, 'n_words': 261}