Sha256: 3c6b3fc70a011ec493d9e16c3822daf087d80f81ffe96fa5e75452c06144f9a6
Contents?: true
Size: 1.1 KB
Versions: 2
Compression:
Stored size: 1.1 KB
Contents
module ActsAsAccount module ActiveRecordExtension def self.included(base) # :nodoc: base.extend ClassMethods base.class_eval do def account(name = :default) __send__("#{name}_account") || __send__("create_#{name}_account", :name => name.to_s, :holder_id => self.id, :holder_type => self.class.to_s) end end end module ClassMethods def has_account(name = :default) has_one "#{name}_account", :conditions => "name = '#{name}'", :class_name => "ActsAsAccount::Account", :as => :holder unless instance_methods.include?('accounts') has_many :accounts, :class_name => "ActsAsAccount::Account", :as => :holder end end def is_reference has_many :postings, :class_name => "ActsAsAccount::Posting", :as => :reference class_eval <<-EOS def booked? postings.any? end EOS end def has_global_account(name) class_eval <<-EOS def account ActsAsAccount::Account.for(:#{name}) end EOS end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
acts_as_account-1.2.0 | lib/acts_as_account/active_record_extensions.rb |
acts_as_account-1.1.6 | lib/acts_as_account/active_record_extensions.rb |