Sha256: 4746180e165abfebbd58cfebbce301e20511fb2671c838db2e7203a237ca19ac

Contents?: true

Size: 832 Bytes

Versions: 1

Compression:

Stored size: 832 Bytes

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.
  def self.open
    where("firm_name = ?", "37signals")
  end

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

  validate :check_empty_credit_limit

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

    def private_method
      "Sir, yes sir!"
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-on-quails-0.1.0 activerecord/test/models/account.rb