Class: Cornerstore::Product::Resource

Inherits:
Resource::Base show all
Includes:
Resource::Filter, Resource::Remote
Defined in:
lib/cornerstore/api/product.rb

Instance Attribute Summary

Attributes inherited from Resource::Base

#parent

Instance Method Summary collapse

Methods included from Resource::Filter

#limit, #offset, #set_filter

Methods included from Resource::Remote

#fetch, #fetch_all, #find_by_id, #to_a, #url

Methods inherited from Resource::Base

#all, #each, #empty?, #find, #find_by_id, #find_by_id_or_param, #find_by_ids, #from_array, #initialize, #method_missing, #push, #size, #to_a

Constructor Details

This class inherits a constructor from Cornerstore::Resource::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Cornerstore::Resource::Base

Instance Method Details

#by_collection(collection_id) ⇒ Object Also known as: find_by_collection



58
59
60
# File 'lib/cornerstore/api/product.rb', line 58

def by_collection(collection_id)
  self.clone.tap{|r| r.parent = Cornerstore::Collection.find(collection_id)}
end

#enabledObject



54
55
56
# File 'lib/cornerstore/api/product.rb', line 54

def enabled
  self.clone.set_filter(:enabled, true)
end

#order(key) ⇒ Object Also known as: order_by



63
64
65
66
67
68
69
# File 'lib/cornerstore/api/product.rb', line 63

def order(key)
  first = %w(name popularity created_at price)
  second = %w(desc asc)
  pattern = /\A(#{first.join('|')})( (#{second.join('|')}))?\z/i
  raise "order key must be one of: #{first.join(', ')} [#{second.join(', ')}]" unless key.match pattern
  super
end