Sha256: 56d71c32d0d53ca76c9ca4481ea103c49d78c6f17818518efb6071ac3a6e97f2
Contents?: true
Size: 983 Bytes
Versions: 2
Compression:
Stored size: 983 Bytes
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) 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 has_postings has_many :postings, :class_name => "ActsAsAccount::Posting", :as => :reference 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.1.1 | lib/acts_as_account/active_record_extensions.rb |
acts_as_account-1.1.0 | lib/acts_as_account/active_record_extensions.rb |