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_type ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/erp_base_erp_svcs/extensions/active_record/acts_as_erp_type.rb', line 21 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 indentifier # 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 ActsAsErpType.models.push(self.name) ActsAsErpType.models.uniq! end |
#belongs_to_erp_type(model_id = nil, options = {}) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/erp_base_erp_svcs/extensions/active_record/acts_as_erp_type.rb', line 44 def belongs_to_erp_type(model_id = nil, = {}) @model_id = model_id self.belongs_to model_id, extend ActsAsErpType::BelongsToSingletonMethods include ActsAsErpType::BelongsToInstanceMethods end |