app/models/plutus/amount.rb in plutus-0.10.1 vs app/models/plutus/amount.rb in plutus-0.11.0
- old
+ new
@@ -1,14 +1,33 @@
module Plutus
# The Amount class represents debit and credit amounts in the system.
#
# @abstract
- # An amount must be a subclass as either a debit or a credit to be saved to the database.
+ # An amount must be a subclass as either a debit or a credit to be saved to the database.
#
# @author Michael Bulat
class Amount < ActiveRecord::Base
belongs_to :entry, :class_name => 'Plutus::Entry'
belongs_to :account, :class_name => 'Plutus::Account'
validates_presence_of :type, :amount, :entry, :account
+ # attr_accessible :account, :account_name, :amount, :entry
+
+ # Assign an account by name
+ def account_name=(name)
+ self.account = Account.find_by_name!(name)
+ end
+
+ protected
+
+ # Support constructing amounts with account = "name" syntax
+ def account_with_name_lookup=(v)
+ if v.kind_of?(String)
+ ActiveSupport::Deprecation.warn('Plutus was given an :account String (use account_name instead)', caller)
+ self.account_name = v
+ else
+ self.account_without_name_lookup = v
+ end
+ end
+ alias_method_chain :account=, :name_lookup
end
end