Class: Workarea::ProductRule
Constant Summary
collapse
- OPERATORS =
%w(
greater_than
greater_than_or_equal
equals
not_equal
less_than
less_than_or_equal
)
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Releasable
#changesets_with_children, #destroy, #in_release, #release_changes, #release_originals, #save_changeset, #skip_changeset, #without_release
#active?, #active_segment_ids_with_children, #segmented?, #segments
#activate_with?, #create_activation_changeset, #save_activate_with, #was_active?
#releasable?
add_worker, assert_valid_config!, async, caching_classes?, disable, enable, inline, #run_callbacks, workers, workers_list
#embedded_children
Class Method Details
.usable ⇒ Object
26
27
28
|
# File 'app/models/workarea/product_rule.rb', line 26
def self.usable
scoped.select(&:active?).select(&:valid?)
end
|
Instance Method Details
#category? ⇒ Boolean
Determines if the rule is a for a category.
113
114
115
|
# File 'app/models/workarea/product_rule.rb', line 113
def category?
slug == :category
end
|
#comparison? ⇒ Boolean
100
101
102
103
104
105
106
107
|
# File 'app/models/workarea/product_rule.rb', line 100
def comparison?
operator.in?([
'greater_than',
'greater_than_or_equal',
'less_than',
'less_than_or_equal'
])
end
|
#created_at? ⇒ Boolean
80
81
82
|
# File 'app/models/workarea/product_rule.rb', line 80
def created_at?
slug == :created_at
end
|
#equality? ⇒ Boolean
84
85
86
|
# File 'app/models/workarea/product_rule.rb', line 84
def equality?
operator == 'equals'
end
|
#false? ⇒ Boolean
96
97
98
|
# File 'app/models/workarea/product_rule.rb', line 96
def false?
value.downcase == 'false'
end
|
The field in Elasticsearch this rule checks against
42
43
44
45
|
# File 'app/models/workarea/product_rule.rb', line 42
def field
return if name.blank?
Workarea.config.product_rule_fields[slug] || "facets.#{name.systemize}"
end
|
#inequality? ⇒ Boolean
88
89
90
|
# File 'app/models/workarea/product_rule.rb', line 88
def inequality?
operator == 'not_equal'
end
|
#inventory? ⇒ Boolean
76
77
78
|
# File 'app/models/workarea/product_rule.rb', line 76
def inventory?
slug == :inventory
end
|
#product_exclusion? ⇒ Boolean
117
118
119
|
# File 'app/models/workarea/product_rule.rb', line 117
def product_exclusion?
slug == :excluded_products
end
|
#sale? ⇒ Boolean
68
69
70
|
# File 'app/models/workarea/product_rule.rb', line 68
def sale?
slug == :on_sale
end
|
#search? ⇒ Boolean
72
73
74
|
# File 'app/models/workarea/product_rule.rb', line 72
def search?
slug == :search
end
|
#slug ⇒ Symbol
The identifier for which admin partials to render for this rule.
34
35
36
|
# File 'app/models/workarea/product_rule.rb', line 34
def slug
name.systemize.to_sym if name.present?
end
|
#terms ⇒ Array<String>
Used in query-building for Elasticsearch
125
126
127
|
# File 'app/models/workarea/product_rule.rb', line 125
def terms
value.to_s.split(',').map(&:strip).reject(&:blank?)
end
|
#true? ⇒ Boolean
92
93
94
|
# File 'app/models/workarea/product_rule.rb', line 92
def true?
value.downcase == 'true'
end
|
#value ⇒ Comparable
Returns the value that the rule uses to compare.
53
54
55
56
|
# File 'app/models/workarea/product_rule.rb', line 53
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. :(
60
61
62
63
64
65
66
|
# File 'app/models/workarea/product_rule.rb', line 60
def value=(val)
if val.is_a?(Array)
super(val.join(','))
else
super(val)
end
end
|
#value_field ⇒ Object
47
|
# File 'app/models/workarea/product_rule.rb', line 47
alias_method :value_field, :value
|