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



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_klassesObject



39
40
41
# File 'lib/opensteam/finder.rb', line 39

def find_product_klasses
  find_product_tables.collect(&:classify).collect(&:constantize)
end

#find_product_tablesObject

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_productsObject

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_propertiesObject

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_tablesObject

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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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