<commit_before>class Account < ApplicationRecord
  include Encryption
  strip_attributes

  [:name, :bic, :iban, :bank, :owner].each do |attr|
    #TODO: Reencrypt with new mode and algorithm
    attr_encrypted attr, key: encryption_key #, mode: :per_attribute_iv_and_salt, algorithm: 'aes-256-cbc', insecure_mode: true
    #attr_encrypted attr, key: encryption_key, mode: :per_attribute_iv_and_salt, algorithm: 'aes-256-cbc', insecure_mode: true
  end

  belongs_to :address
  has_many :credit_agreements, dependent: :restrict_with_exception, inverse_of: :account
  has_many :payments, through: :credit_agreements

  delegate :funded_credits_sum, :average_rate_of_interest, to: :credit_agreements
  delegate :belongs_to_project?, to: :address

  before_save :set_address_type
  after_save :delete_old_default

  validates_presence_of :bank, :iban
  validates_presence_of :name, if: :belongs_to_project?
  validates_with IbanValidator
  validates_with BicValidator

  scope :project_accounts, -> { where(address_type: 'ProjectAddress') }

  private
    def set_address_type
      self.address_type = address.class.to_s
    end

    def delete_old_default
      return unless default
      old_default.update(default: false)
    end

    def old_default
      Account.where(address_id: address_id, default: true).where.not(id: id).first || NullAccount.new
    end
end

class NullAccount
  def method_missing(*)
  end
end
<commit_msg>deleted only comments<commit_after>class Account < ApplicationRecord
  include Encryption
  strip_attributes

  [:name, :bic, :iban, :bank, :owner].each do |attr|
    attr_encrypted attr, key: encryption_key 
  end

  belongs_to :address
  has_many :credit_agreements, dependent: :restrict_with_exception, inverse_of: :account
  has_many :payments, through: :credit_agreements

  delegate :funded_credits_sum, :average_rate_of_interest, to: :credit_agreements
  delegate :belongs_to_project?, to: :address

  before_save :set_address_type
  after_save :delete_old_default

  validates_presence_of :bank, :iban
  validates_presence_of :name, if: :belongs_to_project?
  validates_with IbanValidator
  validates_with BicValidator

  scope :project_accounts, -> { where(address_type: 'ProjectAddress') }

  private
    def set_address_type
      self.address_type = address.class.to_s
    end

    def delete_old_default
      return unless default
      old_default.update(default: false)
    end

    def old_default
      Account.where(address_id: address_id, default: true).where.not(id: id).first || NullAccount.new
    end
end

class NullAccount
  def method_missing(*)
  end
end

{'fraction_non_alphanumeric': 0.07957153787299158, 'fraction_numerical': 0.0022953328232593728, 'mean_word_length': 4.811111111111111, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5963718', 'n_tokens_mistral': 883, 'n_tokens_neox': 832, 'n_words': 201}