Module: Opensteam::Finder::ClassMethods

Defined in:
lib/opensteam/finder.rb

Instance Method Summary collapse

Instance Method Details

#find_product(klass) ⇒ Object

find all products of the specified Class



69
70
71
# File 'lib/opensteam/finder.rb', line 69

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



74
75
76
77
# File 'lib/opensteam/finder.rb', line 74

def find_product_by_id(klass,id)
  return nil if id.empty?
  contantize_pro(:product,klass).find(id)
end

#find_product_tablesObject

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



44
45
46
# File 'lib/opensteam/finder.rb', line 44

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 } 
}


32
33
34
35
36
37
38
39
# File 'lib/opensteam/finder.rb', line 32

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_productsObject

find all products



50
51
52
# File 'lib/opensteam/finder.rb', line 50

def find_products
  find_product_tables.inject([]) { |r,v| r += v.classify.constantize.find(:all) }
end

#find_propertiesObject

find all properties



62
63
64
65
# File 'lib/opensteam/finder.rb', line 62

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



80
81
82
# File 'lib/opensteam/finder.rb', line 80

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



85
86
87
88
# File 'lib/opensteam/finder.rb', line 85

def find_property_by_id(klass,id)
  return nil if id.empty?
  contantize_pro(:property, klass).find(id)
end

#find_property_tablesObject

find property tables



56
57
58
59
# File 'lib/opensteam/finder.rb', line 56

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

Returns:

  • (Boolean)


91
92
93
# File 'lib/opensteam/finder.rb', line 91

def inventories_properties_exist?
  not ActiveRecord::Base.connection.select_all("SHOW TABLES LIKE 'inventories_properties'").empty?
end

#properties_table_exists?Boolean

checks if the properties table exists

Returns:

  • (Boolean)


96
97
98
# File 'lib/opensteam/finder.rb', line 96

def properties_table_exists?
  not ActiveRecord::Base.connection.select_all("SHOW TABLES LIKE 'properties'").empty?
end