Class: Dugway::Drops::ProductsDrop
- Defined in:
- lib/dugway/liquid/drops/products_drop.rb
Instance Attribute Summary
Attributes inherited from BaseDrop
Instance Method Summary collapse
- #all ⇒ Object
-
#before_method(method_or_key) ⇒ Object
Also ensure before_method works as fallback.
- #current ⇒ Object
-
#liquid_method_missing(method) ⇒ Object
Liquid 5.x compatibility: implement liquid_method_missing for method access.
- #on_sale ⇒ Object
Methods inherited from BaseDrop
#as_json, #cart, #context=, #error, #errors, #initialize, #method_missing, #store, #theme, #to_liquid
Constructor Details
This class inherits a constructor from Dugway::Drops::BaseDrop
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Dugway::Drops::BaseDrop
Instance Method Details
#all ⇒ Object
45 46 47 |
# File 'lib/dugway/liquid/drops/products_drop.rb', line 45 def all sort_and_paginate source end |
#before_method(method_or_key) ⇒ Object
Also ensure before_method works as fallback
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dugway/liquid/drops/products_drop.rb', line 32 def before_method(method_or_key) case method_or_key.to_s when 'all' all when 'current' current when 'on_sale' on_sale else super end end |
#current ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/dugway/liquid/drops/products_drop.rb', line 49 def current sort_and_paginate begin if artist.present? dropify store.artist_products(artist) elsif category.present? dropify store.category_products(category) elsif search_terms.present? dropify store.search_products(search_terms) else source end end end |
#liquid_method_missing(method) ⇒ Object
Liquid 5.x compatibility: implement liquid_method_missing for method access
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dugway/liquid/drops/products_drop.rb', line 8 def liquid_method_missing(method) method_str = method.to_s # Handle known methods case method_str when 'all' all when 'current' current when 'on_sale' on_sale else # Try to find product by permalink result = before_method(method_str) # Wrap hash results in ProductDrop if it looks like a product if result.is_a?(Hash) && result['permalink'] ProductDrop.new(result) else result end end end |
#on_sale ⇒ Object
63 64 65 |
# File 'lib/dugway/liquid/drops/products_drop.rb', line 63 def on_sale sort_and_paginate source.select { |p| p['on_sale'] } end |