Class: Dugway::Drops::BaseDrop
- Inherits:
-
Liquid::Drop
- Object
- Liquid::Drop
- Dugway::Drops::BaseDrop
show all
- Defined in:
- lib/dugway/liquid/drops/base_drop.rb
Direct Known Subclasses
AccountDrop, ArtistDrop, ArtistsDrop, CartDrop, CartItemDrop, CategoriesDrop, CategoryDrop, ContactDrop, CountryDrop, CurrencyDrop, FeaturesDrop, ImageDrop, OptionGroupDrop, OptionGroupValueDrop, PageDrop, PagesDrop, ProductDrop, ProductOptionDrop, ProductsDrop, RelatedProductsDrop, ShippingOptionDrop, ThemeDrop, ThemeImageSetsDrop, ThemeImagesDrop, TranslationsDrop
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(source = nil) ⇒ BaseDrop
Returns a new instance of BaseDrop.
8
9
10
|
# File 'lib/dugway/liquid/drops/base_drop.rb', line 8
def initialize(source=nil)
@source = source
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
51
52
53
|
# File 'lib/dugway/liquid/drops/base_drop.rb', line 51
def method_missing(method, *args, &block)
before_method(method.to_s)
end
|
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
6
7
8
|
# File 'lib/dugway/liquid/drops/base_drop.rb', line 6
def params
@params
end
|
#request ⇒ Object
Returns the value of attribute request.
5
6
7
|
# File 'lib/dugway/liquid/drops/base_drop.rb', line 5
def request
@request
end
|
#source ⇒ Object
Returns the value of attribute source.
4
5
6
|
# File 'lib/dugway/liquid/drops/base_drop.rb', line 4
def source
@source
end
|
Instance Method Details
#as_json(*args) ⇒ Object
74
75
76
77
78
79
80
81
|
# File 'lib/dugway/liquid/drops/base_drop.rb', line 74
def as_json(*args)
if source.is_a?(Hash)
source.stringify_keys
else
{}
end
end
|
#before_method(method_or_key) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/dugway/liquid/drops/base_drop.rb', line 30
def before_method(method_or_key)
if respond_to?(method_or_key)
elsif source.respond_to?(method_or_key)
return source.send(method_or_key)
elsif source.respond_to?('has_key?') && source.has_key?(method_or_key)
return source[method_or_key]
elsif source.is_a?(Array) && source.first
for item in source
if item.is_a?(Hash) && item['permalink'] == method_or_key.to_s
return item
elsif item.respond_to?(:source) && item.source.is_a?(Hash) && item.source['permalink'] == method_or_key.to_s
return item
end
end
end
nil
end
|
#cart ⇒ Object
26
27
28
|
# File 'lib/dugway/liquid/drops/base_drop.rb', line 26
def cart
Dugway.cart
end
|
#context=(current_context) ⇒ Object
12
13
14
15
16
|
# File 'lib/dugway/liquid/drops/base_drop.rb', line 12
def context=(current_context)
@request = current_context.registers[:request]
@params = current_context.registers[:params]
super
end
|
#error(msg) ⇒ Object
64
65
66
|
# File 'lib/dugway/liquid/drops/base_drop.rb', line 64
def error(msg)
errors << msg
end
|
#errors ⇒ Object
60
61
62
|
# File 'lib/dugway/liquid/drops/base_drop.rb', line 60
def errors
@context['errors']
end
|
#liquid_method_missing(method_name) ⇒ Object
Liquid 5.x compatibility: implement liquid_method_missing for property access
56
57
58
|
# File 'lib/dugway/liquid/drops/base_drop.rb', line 56
def liquid_method_missing(method_name)
before_method(method_name.to_s)
end
|
#store ⇒ Object
18
19
20
|
# File 'lib/dugway/liquid/drops/base_drop.rb', line 18
def store
Dugway.store
end
|
#theme ⇒ Object
22
23
24
|
# File 'lib/dugway/liquid/drops/base_drop.rb', line 22
def theme
Dugway.theme
end
|
#to_liquid ⇒ Object
Liquid 5.x compatibility: make drops JSON-serializable Only return source for JSON serialization, not for filter processing
70
71
72
|
# File 'lib/dugway/liquid/drops/base_drop.rb', line 70
def to_liquid
self
end
|