Module: ErpProducts::Extensions::ActiveRecord::ActsAsProductType::ClassMethods

Defined in:
lib/erp_products/extensions/active_record/acts_as_product_type.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_children(parent_id = nil) ⇒ Object



28
29
30
# File 'lib/erp_products/extensions/active_record/acts_as_product_type.rb', line 28

def self.find_children(parent_id = nil)
  ProductType.find_children(parent_id)
end

.find_rootsObject



24
25
26
# File 'lib/erp_products/extensions/active_record/acts_as_product_type.rb', line 24

def self.find_roots
  ProductType.find_roots
end

Instance Method Details

#acts_as_product_typeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/erp_products/extensions/active_record/acts_as_product_type.rb', line 11

def acts_as_product_type()
  extend ActsAsProductType::SingletonMethods
  include ActsAsProductType::InstanceMethods

  after_initialize :initialize_product_type
  after_create :save_product_type
  after_update :save_product_type
  after_destroy :destroy_product_type

  has_one :product_type, :as => :product_type_record

  [:children, :description, :description=].each do |m| delegate m, :to => :product_type end

  def self.find_roots
    ProductType.find_roots
  end

  def self.find_children(parent_id = nil)
    ProductType.find_children(parent_id)
  end
end