Class: Workarea::ProductRule
Constant Summary
collapse
- OPERATORS =
%w(
greater_than
greater_than_or_equal
equals
not_equal
less_than
less_than_or_equal
)
Instance Method Summary
collapse
#releasable?
add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list
Instance Method Details
#category? ⇒ Boolean
Determines if the rule is a for a category.
108
109
110
|
# File 'app/models/workarea/product_rule.rb', line 108
def category?
slug == :category
end
|
#comparison? ⇒ Boolean
95
96
97
98
99
100
101
102
|
# File 'app/models/workarea/product_rule.rb', line 95
def comparison?
operator.in?([
'greater_than',
'greater_than_or_equal',
'less_than',
'less_than_or_equal'
])
end
|
#created_at? ⇒ Boolean
75
76
77
|
# File 'app/models/workarea/product_rule.rb', line 75
def created_at?
slug == :created_at
end
|
#equality? ⇒ Boolean
79
80
81
|
# File 'app/models/workarea/product_rule.rb', line 79
def equality?
operator == 'equals'
end
|
#false? ⇒ Boolean
91
92
93
|
# File 'app/models/workarea/product_rule.rb', line 91
def false?
value.downcase == 'false'
end
|
The field in Elasticsearch this rule checks against
37
38
39
40
|
# File 'app/models/workarea/product_rule.rb', line 37
def field
return if name.blank?
Workarea.config.product_rule_fields[slug] || "facets.#{name.systemize}"
end
|
#inequality? ⇒ Boolean
83
84
85
|
# File 'app/models/workarea/product_rule.rb', line 83
def inequality?
operator == 'not_equal'
end
|
#inventory? ⇒ Boolean
71
72
73
|
# File 'app/models/workarea/product_rule.rb', line 71
def inventory?
slug == :inventory
end
|
#product_exclusion? ⇒ Boolean
112
113
114
|
# File 'app/models/workarea/product_rule.rb', line 112
def product_exclusion?
slug == :excluded_products
end
|
#sale? ⇒ Boolean
63
64
65
|
# File 'app/models/workarea/product_rule.rb', line 63
def sale?
slug == :on_sale
end
|
#search? ⇒ Boolean
67
68
69
|
# File 'app/models/workarea/product_rule.rb', line 67
def search?
slug == :search
end
|
#slug ⇒ Symbol
The identifier for which admin partials to render for this rule.
29
30
31
|
# File 'app/models/workarea/product_rule.rb', line 29
def slug
name.systemize.to_sym if name.present?
end
|
#terms ⇒ Array<String>
Used in query-building for Elasticsearch
120
121
122
|
# File 'app/models/workarea/product_rule.rb', line 120
def terms
value.to_s.split(',').map(&:strip).reject(&:blank?)
end
|
#true? ⇒ Boolean
87
88
89
|
# File 'app/models/workarea/product_rule.rb', line 87
def true?
value.downcase == 'true'
end
|
#value ⇒ Comparable
Returns the value that the rule uses to compare.
48
49
50
51
|
# File 'app/models/workarea/product_rule.rb', line 48
def value
return Time.zone.parse(value_field) rescue value_field if created_at?
value_field
end
|
#value=(val) ⇒ Object
This is HACK for the fact that we want a CSV string in value, but our current solution for submitting category IDs submits an array. :(
55
56
57
58
59
60
61
|
# File 'app/models/workarea/product_rule.rb', line 55
def value=(val)
if val.is_a?(Array)
super(val.join(','))
else
super(val)
end
end
|
#value_field ⇒ Object
42
|
# File 'app/models/workarea/product_rule.rb', line 42
alias_method :value_field, :value
|