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



64
65
66
67
68
69
70
71
# File 'lib/opensteam/product_base.rb', line 64

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) 

  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



54
55
56
57
# File 'lib/opensteam/product_base.rb', line 54

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



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

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

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



41
42
43
# File 'lib/opensteam/product_base.rb', line 41

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

#table_nameObject



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

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_”



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

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