class Cacofonix::ProductBase
This is the abstract base class of Product, RelatedProduct and ContainedItem.
Public Instance Methods
interpret(mods)
click to toggle source
Extend this product instance with a module. Typically these modules make it easier to read or write common values in the Product.
The product tracks the modules that have extended it, so that it can easily pass these extensions on to other products (see interpret_like_me
).
For convenience, this method returns the product itself.
# File lib/cacofonix/elements/product_base.rb, line 34 def interpret(mods) @_extensions ||= [] [mods].flatten.compact.uniq.each { |mod| next if @_extensions.include?(mod) @_extensions << mod extend(mod) } self end
interpret_like_me(product)
click to toggle source
Apply all the modules that have extended this product to another product.
This is useful when, say, accessing RelatedProduct or ContainedItem composites. Your module might do something like:
def print_product prod = related_products.detect { |p| p.relation_code == 13 } prod ? interpret_like_me(prod) : nil end
As a result, this related product will have all the extensions applied to this product.
# File lib/cacofonix/elements/product_base.rb, line 57 def interpret_like_me(product) product.interpret(@_extensions) end