Sha256: 9ca788453ce883a96c6a0f406ceb898c864d8be1dad03f9b0b9edbfb79b07a16

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

class Account < ActiveRecord::Base
  belongs_to :firm, class_name: "Company"
  belongs_to :unautosaved_firm, foreign_key: "firm_id", class_name: "Firm", autosave: false

  alias_attribute :available_credit, :credit_limit

  def self.destroyed_account_ids
    @destroyed_account_ids ||= Hash.new { |h, k| h[k] = [] }
  end

  # Test private kernel method through collection proxy using has_many.
  scope :open, -> { where("firm_name = ?", "37signals") }
  scope :available, -> { open }

  before_destroy do |account|
    if account.firm
      Account.destroyed_account_ids[account.firm.id] << account.id
    end
  end

  validate :check_empty_credit_limit
  validate :ensure_good_credit, on: :bank_loan

  private
    def check_empty_credit_limit
      errors.add("credit_limit", :blank) if credit_limit.blank?
    end

    def ensure_good_credit
      errors.add(:credit_limit, "too low") unless credit_limit > 10_000
    end

    def private_method
      "Sir, yes sir!"
    end
end

class SubAccount < Account
  def self.instantiate_instance_of(klass, attributes, column_types = {}, &block)
    klass = superclass
    super
  end
  private_class_method :instantiate_instance_of
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ibm_db-5.5.0-x86-mingw32 test/models/account.rb
ibm_db-5.4.1-x86-mingw32 test/models/account.rb
ibm_db-5.4.0-x86-mingw32 test/models/account.rb
ibm_db-5.3.2-x86-mingw32 test/models/account.rb