Module: Opensteam::Finder::ClassMethods
- Defined in:
- lib/opensteam/finder.rb
Instance Method Summary collapse
-
#find_product(klass) ⇒ Object
find all products of the specified Class.
-
#find_product_by_id(klass, id) ⇒ Object
find a product specified by klass and id.
- #find_product_klasses ⇒ Object
-
#find_product_tables ⇒ Object
find all product tables (tables prefixed with Opensteam::Config::PRODUCT_BASE_TABLE_PREFIX) TODO : implement paginate for finder.
-
#find_product_with_inventory(h) ⇒ Object
method is invoked before adding a product to the cart.
-
#find_products ⇒ Object
find all products.
-
#find_properties ⇒ Object
find all properties.
-
#find_property(klass) ⇒ Object
find all properties of the specified Class.
-
#find_property_by_id(klass, id) ⇒ Object
find a property by klass and id.
-
#find_property_tables ⇒ Object
find property tables.
-
#inventories_properties_exist? ⇒ Boolean
checks if the “inventories_properties” table exists.
-
#properties_table_exists? ⇒ Boolean
checks if the properties table exists.
Instance Method Details
#find_product(klass) ⇒ Object
find all products of the specified Class
91 92 93 |
# File 'lib/opensteam/finder.rb', line 91 def find_product(klass) contantize_pro(:product, klass).find(:all) end |
#find_product_by_id(klass, id) ⇒ Object
find a product specified by klass and id
96 97 98 99 |
# File 'lib/opensteam/finder.rb', line 96 def find_product_by_id(klass,id) return nil if id.empty? contantize_pro(:product,klass).find(id) end |
#find_product_klasses ⇒ Object
39 40 41 |
# File 'lib/opensteam/finder.rb', line 39 def find_product_klasses find_product_tables.collect(&:classify).collect(&:constantize) end |
#find_product_tables ⇒ Object
find all product tables (tables prefixed with Opensteam::Config::PRODUCT_BASE_TABLE_PREFIX) TODO : implement paginate for finder
66 67 68 |
# File 'lib/opensteam/finder.rb', line 66 def find_product_tables find_tables("product") end |
#find_product_with_inventory(h) ⇒ Object
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 Hash,:
params[:product] = { :class => "ProductClass", :id => 1,
:properties => { "Color" => 2, "Size" => 5 }
}
54 55 56 57 58 59 60 61 |
# File 'lib/opensteam/finder.rb', line 54 def find_product_with_inventory( h ) product = find_product_by_id( h[:class], h[:id] ) props = h[:properties] ? h[:properties].collect { |x| find_property_by_id( x.first, x.last ) } : [] product.selected_inventory = product.inventories( props ) product end |
#find_products ⇒ Object
find all products
72 73 74 |
# File 'lib/opensteam/finder.rb', line 72 def find_products find_product_tables.inject([]) { |r,v| r += v.classify.constantize.find(:all) } end |
#find_properties ⇒ Object
find all properties
84 85 86 87 |
# File 'lib/opensteam/finder.rb', line 84 def find_properties Properties.find(:all) # find_property_tables.inject([]) { |r,v| r += v.classify.constantize.find(:all) } end |
#find_property(klass) ⇒ Object
find all properties of the specified Class
102 103 104 |
# File 'lib/opensteam/finder.rb', line 102 def find_property(klass) contantize_pro(:property,klass).find(:all) end |
#find_property_by_id(klass, id) ⇒ Object
find a property by klass and id
107 108 109 110 |
# File 'lib/opensteam/finder.rb', line 107 def find_property_by_id(klass,id) return nil if id.empty? contantize_pro(:property, klass).find(id) end |
#find_property_tables ⇒ Object
find property tables
78 79 80 81 |
# File 'lib/opensteam/finder.rb', line 78 def find_property_tables Opensteam::Base::PropertyBase.properties.collect(&:tableize) # find_tables("property") end |
#inventories_properties_exist? ⇒ Boolean
checks if the “inventories_properties” table exists
115 116 117 118 |
# File 'lib/opensteam/finder.rb', line 115 def inventories_properties_exist? ActiveRecord::Base.connection.tables.include?( "inventories_properties" ) # not ActiveRecord::Base.connection.select_all("SHOW TABLES LIKE 'inventories_properties'").empty? end |
#properties_table_exists? ⇒ Boolean
checks if the properties table exists
121 122 123 124 |
# File 'lib/opensteam/finder.rb', line 121 def properties_table_exists? ActiveRecord::Base.connection.tables.include?( "properties" ) # not ActiveRecord::Base.connection.select_all("SHOW TABLES LIKE 'properties'").empty? end |