Module: Opensteam::ProductBase::ClassMethods

Defined in:
lib/opensteam/product_base.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#get_has_productsObject

get all product-objects (records) for current product (used for bundle-products) to define the products the current bundle-product is allowed to have use:

  • *has_product :peoduct_model* in ProductModel

default: no products



48
49
50
51
52
53
54
55
# File 'lib/opensteam/product_base.rb', line 48

def get_has_products
  products = (self._has_product || []).inject({}) { |r,v|
    r.merge!( { v => v.to_s.classify.constantize.find(:all) } ) }  || {}

  products.delete(self.to_s.tableize) #unless <%= class_name %>.self.referential

  products
end

#get_has_propertyObject

get all property-objects (records) for current product to define the properties the product is allowed to have use:

  • *has_property :property_class* in ProductModel

default: all properties



38
39
40
41
# File 'lib/opensteam/product_base.rb', line 38

def get_has_property
  (self._has_property.nil? ? self.find_property_tables : self._has_property).inject({}) { |r,v|
    r.merge!( { v => v.to_s.classify.constantize.find(:all) } ) unless v.first == :none } || {}
end

#has_product(p) ⇒ Object



29
# File 'lib/opensteam/product_base.rb', line 29

def has_product(p) (self._has_product ||= []) << p if p ; end

#has_property(p = nil, opt = nil) ⇒ Object



25
26
27
# File 'lib/opensteam/product_base.rb', line 25

def has_property(p = nil, opt = nil )
  p ? ( self._has_property ||= {} ).store(p, opt) : ( self._has_property ||= {} )
end

#table_nameObject



23
# File 'lib/opensteam/product_base.rb', line 23

def table_name() self.table_prefix + "_" + self.to_s.tableize ; end

#table_prefixObject

define table_name and prefix all product-tables are prefixed with “product_”



22
# File 'lib/opensteam/product_base.rb', line 22

def table_prefix() Opensteam::Config::PRODUCT_BASE_TABLE_PREFIX.to_s ; end