Module: ErpBaseErpSvcs::Extensions::ActiveRecord::ActsAsErpType::ClassMethods

Defined in:
lib/erp_base_erp_svcs/extensions/active_record/acts_as_erp_type.rb

Overview

declare the class level helper methods which will load the relevant instance methods defined below when invoked

Instance Method Summary collapse

Instance Method Details

#acts_as_erp_typeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/erp_base_erp_svcs/extensions/active_record/acts_as_erp_type.rb', line 14

def acts_as_erp_type
	
      # this is at the class level
      # add any class level manipulations you need here, like has_many, etc.
      extend ActsAsErpType::ActsAsSingletonMethods
      include ActsAsErpType::ActsAsInstanceMethods
	
      if ::ActiveRecord::Base.connection.tables.include?(self.table_name)
        # find each valid value for the domain type (erp_type) in question
        # we will then create a class method with the name of the internal idenfifier
        # for that type
        valid_values = self.all
	
        # the class method will return a populated instance of the correct type
        valid_values.each do | vv |
          (class << self; self; end).instance_eval { define_method vv.internal_identifier, Proc.new{vv} } unless vv.internal_identifier.nil?
        end
      end
end

#belongs_to_erp_type(model_id = nil, options = {}) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/erp_base_erp_svcs/extensions/active_record/acts_as_erp_type.rb', line 34

def belongs_to_erp_type(model_id = nil, options = {})

      @model_id = model_id
      self.belongs_to model_id, options
      extend ActsAsErpType::BelongsToSingletonMethods
      include ActsAsErpType::BelongsToInstanceMethods
	
end