Module: Accountable::ActiveRecordExtensions::ActsMethods
- Defined in:
- lib/accountable/active_record_extensions.rb
Instance Method Summary collapse
-
#acts_as_accountee(*args) ⇒ Object
Placed in the model desired to be the accountee (usually User).
-
#acts_as_accountor(*args) ⇒ Object
Placed in the model desired to be the accountor (usually Account).
-
#acts_as_accountors_asset(*args) ⇒ Object
Placed in the model(s) desired to be owned by the accountor.
Instance Method Details
#acts_as_accountee(*args) ⇒ Object
Placed in the model desired to be the accountee (usually User).
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/accountable/active_record_extensions.rb', line 38 def acts_as_accountee( *args ) unless included_modules.include? Accountable::Accountee include Accountable::Accountee = args. self..merge!( .reject { |k,v| v.blank? } ) self.class_eval do belongs_to self.[:of].to_sym validates_presence_of self.[:of].to_sym end end end |
#acts_as_accountor(*args) ⇒ Object
Placed in the model desired to be the accountor (usually Account).
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/accountable/active_record_extensions.rb', line 11 def acts_as_accountor( *args ) unless included_modules.include? Accountable::Accountor include Accountable::Accountor = args. self..merge!( .reject { |k,v| v.blank? } ) self.class_eval do has_many self.[:of], :dependent => [:dependent] unless [:name] == false validates_presence_of [:name].to_sym validates_length_of [:name].to_sym, :maximum => 150, :allow_nil => true, :allow_blank => true attr_accessible [:name].to_sym end assets = self.[:assets].is_a?( Array ) ? self.[:assets] : [self.[:assets]] assets.each { |asset| has_many asset.to_sym, :dependent => [:dependent] } include Accountor::States::StateMachineInstanceMethods unless [:with_state] == false include Accountor::States::AasmTraits if [:with_state] == :aasm include Accountor::States::StateMachineTraits if [:with_state] == :state_machine end end end |
#acts_as_accountors_asset(*args) ⇒ Object
Placed in the model(s) desired to be owned by the accountor.
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/accountable/active_record_extensions.rb', line 53 def acts_as_accountors_asset( *args ) unless included_modules.include? Accountable::AccountorsAsset include Accountable::AccountorsAsset self.class_eval do belongs_to self.[:of] validates_presence_of self.[:of] end end end |