<commit_before>class TransactionsController < ApplicationController
  before_action :load_transaction, only: [:edit, :update, :destroy]

  def index
    @transaction = Transaction.new
    @transactions = Transaction.recent_history.decorate
  end

  def create
    @transaction = Transaction.new(complemented_params)
    begin
      @transaction.save!
      redirect_to transactions_path, notice: 'Transaction created'
    rescue ActiveRecord::RecordInvalid => e
      flash.now[:alert] = e.message
      render :new
    end
  end

  def edit
  end

  def update
    @transaction.assign_attributes(complemented_params)
    begin
      @transaction.save!
      redirect_to transactions_path, notice: 'Transaction updated'
    rescue => e
      flash.now[:alert] = e.message
      render :edit
    end
  end

  def destroy
    fail if @transaction.transfer?
    @transaction.destroy
    redirect_to transactions_url, notice: 'Transaction destroyed'
  end

  private

  def permitted_params
    [
      :account_id,
      :amount,
      :amount_currency,
      :direction,
      :memo,
      :category_id,
      :created_at
    ]
  end

  def complemented_params
    transaction_params.merge(kind: kind, direction: direction)
  end

  def transaction_params
    params.require(:transaction).permit(permitted_params)
  end

  def direction
    (transaction_params[:direction] == 'inflow') ? Const::INFLOW : Const::OUTFLOW
  end

  def kind
    (direction == 'inflow') ? Const::INCOME : Const::EXPENSE
  end

  def processed_params
    transaction_params.merge(created_at: created_at)
  end

  def created_at
    Date.strptime(params[:created_at], Const::DATEPICKER_FORMAT_PARSE)
  end
<commit_msg>Direction fix<commit_after>class TransactionsController < ApplicationController
  before_action :load_transaction, only: [:edit, :update, :destroy]

  def index
    @transaction = Transaction.new
    @transactions = Transaction.recent_history.decorate
  end

  def create
    @transaction = Transaction.new(complemented_params)
    begin
      @transaction.save!
      redirect_to transactions_path, notice: 'Transaction created'
    rescue ActiveRecord::RecordInvalid => e
      flash.now[:alert] = e.message
      render :new
    end
  end

  def edit
  end

  def update
    @transaction.assign_attributes(complemented_params)
    begin
      @transaction.save!
      redirect_to transactions_path, notice: 'Transaction updated'
    rescue => e
      flash.now[:alert] = e.message
      render :edit
    end
  end

  def destroy
    fail if @transaction.transfer?
    @transaction.destroy
    redirect_to transactions_url, notice: 'Transaction destroyed'
  end

  private

  def permitted_params
    [
      :account_id,
      :amount,
      :amount_currency,
      :direction,
      :memo,
      :category_id,
      :created_at
    ]
  end

  def complemented_params
    transaction_params.merge(kind: kind, direction: direction)
  end

  def transaction_params
    params.require(:transaction).permit(permitted_params)
  end

  def inflow?
    transaction_params[:direction] == 'inflow'
  end

  def direction
    inflow? ? Const::INFLOW : Const::OUTFLOW
  end

  def kind
    inflow? ? Const::INCOME : Const::EXPENSE
  end

  def processed_params
    transaction_params.merge(created_at: created_at)
  end

  def created_at
    Date.strptime(params[:created_at], Const::DATEPICKER_FORMAT_PARSE)
  end

{'fraction_non_alphanumeric': 0.08149455722271257, 'fraction_numerical': 0.0, 'mean_word_length': 3.3092522179974653, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5514668', 'n_tokens_mistral': 1024, 'n_tokens_neox': 991, 'n_words': 234}