Module Opensteam::Finder::ClassMethods
In: lib/opensteam/finder.rb

Methods

Public Instance methods

find all products of the specified Class

[Source]

    # File lib/opensteam/finder.rb, line 91
91:       def find_product(klass)
92:         contantize_pro(:product, klass).find(:all)
93:       end

find a product specified by klass and id

[Source]

    # File lib/opensteam/finder.rb, line 96
96:       def find_product_by_id(klass,id)
97:         return nil if id.empty?
98:         contantize_pro(:product,klass).find(id)
99:       end

[Source]

    # File lib/opensteam/finder.rb, line 39
39:       def find_product_klasses
40:         find_product_tables.collect(&:classify).collect(&:constantize)
41:       end

find all product tables (tables prefixed with Opensteam::Config::PRODUCT_BASE_TABLE_PREFIX) TODO : implement paginate for finder

[Source]

    # File lib/opensteam/finder.rb, line 66
66:       def find_product_tables
67:         find_tables("product")
68:       end

method is invoked before adding a product to the cart

finds the product, specified in h and saves the inventory, based on the selected properties, in the "selected_inventory" var.

h is the params[:product] Hash,:

  params[:product] = { :class => "ProductClass", :id => 1,
    :properties => { "Color" => 2, "Size" => 5 }
  }

[Source]

    # File lib/opensteam/finder.rb, line 54
54:       def find_product_with_inventory( h )
55: 
56:         product = find_product_by_id( h[:class], h[:id] )
57:         props = h[:properties] ? h[:properties].collect { |x| find_property_by_id( x.first, x.last ) } : []
58:         product.selected_inventory = product.inventories( props )
59:         product
60:         
61:       end

find all products

[Source]

    # File lib/opensteam/finder.rb, line 72
72:       def find_products
73:         find_product_tables.inject([]) { |r,v| r += v.classify.constantize.find(:all) }
74:       end

find all properties

[Source]

    # File lib/opensteam/finder.rb, line 84
84:       def find_properties
85:         Properties.find(:all)
86:         #        find_property_tables.inject([]) { |r,v| r += v.classify.constantize.find(:all) }

87:       end

find all properties of the specified Class

[Source]

     # File lib/opensteam/finder.rb, line 102
102:       def find_property(klass)
103:         contantize_pro(:property,klass).find(:all)
104:       end

find a property by klass and id

[Source]

     # File lib/opensteam/finder.rb, line 107
107:       def find_property_by_id(klass,id)
108:         return nil if id.empty?
109:         contantize_pro(:property, klass).find(id)
110:       end

find property tables

[Source]

    # File lib/opensteam/finder.rb, line 78
78:       def find_property_tables
79:         Opensteam::Base::PropertyBase.properties.collect(&:tableize)
80:         #        find_tables("property")

81:       end

checks if the "inventories_properties" table exists

[Source]

     # File lib/opensteam/finder.rb, line 115
115:       def inventories_properties_exist?
116:         ActiveRecord::Base.connection.tables.include?( "inventories_properties" )
117:         #        not ActiveRecord::Base.connection.select_all("SHOW TABLES LIKE 'inventories_properties'").empty?

118:       end

checks if the properties table exists

[Source]

     # File lib/opensteam/finder.rb, line 121
121:       def properties_table_exists?
122:         ActiveRecord::Base.connection.tables.include?( "properties" )
123:         #        not ActiveRecord::Base.connection.select_all("SHOW TABLES LIKE 'properties'").empty?

124:       end

[Validate]