module ErpBaseErpSvcs::Extensions::ActiveRecord::ActsAsErpType::ClassMethods

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

Public Instance Methods

acts_as_erp_type() click to toggle source
# 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 = {}) click to toggle source
# File lib/erp_base_erp_svcs/extensions/active_record/acts_as_erp_type.rb, line 44
                      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