Class: Trample::ConditionProxy
- Inherits:
-
Object
- Object
- Trample::ConditionProxy
- Defined in:
- lib/trample/condition_proxy.rb
Instance Method Summary collapse
- #analyzed(value) ⇒ Object
- #and(values) ⇒ Object (also: #all)
- #any_text(value) ⇒ Object
- #autocomplete(value) ⇒ Object
- #eq(value) ⇒ Object
- #gt(value) ⇒ Object
- #gte(value) ⇒ Object
-
#initialize(name, search) ⇒ ConditionProxy
constructor
A new instance of ConditionProxy.
- #lt(value) ⇒ Object
- #lte(value) ⇒ Object
- #not(values) ⇒ Object (also: #not_in)
- #or(values) ⇒ Object (also: #in)
- #set(payload) ⇒ Object
- #starts_with(value) ⇒ Object
- #within(range) ⇒ Object
- #within_eq(range) ⇒ Object
Constructor Details
#initialize(name, search) ⇒ ConditionProxy
Returns a new instance of ConditionProxy.
4 5 6 7 8 9 10 11 12 |
# File 'lib/trample/condition_proxy.rb', line 4 def initialize(name, search) condition = search.class._conditions[name.to_sym] raise ConditionNotFoundError.new(search, name) unless condition @condition_class = condition.class @condition_config = condition.attributes.dup @search = search @name = name.to_sym end |
Instance Method Details
#analyzed(value) ⇒ Object
24 25 26 |
# File 'lib/trample/condition_proxy.rb', line 24 def analyzed(value) set(values: value, search_analyzed: true) end |
#and(values) ⇒ Object Also known as: all
19 20 21 |
# File 'lib/trample/condition_proxy.rb', line 19 def and(values) set(values: values, and: true) end |
#any_text(value) ⇒ Object
69 70 71 |
# File 'lib/trample/condition_proxy.rb', line 69 def any_text(value) set(values: value, any_text: true) end |
#autocomplete(value) ⇒ Object
61 62 63 |
# File 'lib/trample/condition_proxy.rb', line 61 def autocomplete(value) set(values: value, autocomplete: true) end |
#eq(value) ⇒ Object
57 58 59 |
# File 'lib/trample/condition_proxy.rb', line 57 def eq(value) set(values: value) end |
#gt(value) ⇒ Object
37 38 39 |
# File 'lib/trample/condition_proxy.rb', line 37 def gt(value) merge(from: value) end |
#gte(value) ⇒ Object
33 34 35 |
# File 'lib/trample/condition_proxy.rb', line 33 def gte(value) merge(from_eq: value) end |
#lt(value) ⇒ Object
45 46 47 |
# File 'lib/trample/condition_proxy.rb', line 45 def lt(value) merge(to: value) end |
#lte(value) ⇒ Object
41 42 43 |
# File 'lib/trample/condition_proxy.rb', line 41 def lte(value) merge(to_eq: value) end |
#not(values) ⇒ Object Also known as: not_in
28 29 30 |
# File 'lib/trample/condition_proxy.rb', line 28 def not(values) set(values: values, not: true) end |
#or(values) ⇒ Object Also known as: in
14 15 16 |
# File 'lib/trample/condition_proxy.rb', line 14 def or(values) set(values: values, and: false) end |
#set(payload) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/trample/condition_proxy.rb', line 73 def set(payload) payload = {values: payload} unless payload.is_a?(Hash) condition = @condition_class.new(@condition_config.merge(payload)) @search.conditions[@name] = condition @search end |
#starts_with(value) ⇒ Object
65 66 67 |
# File 'lib/trample/condition_proxy.rb', line 65 def starts_with(value) set(values: value, prefix: true) end |
#within(range) ⇒ Object
49 50 51 |
# File 'lib/trample/condition_proxy.rb', line 49 def within(range) set(from: range.first, to: range.last) end |
#within_eq(range) ⇒ Object
53 54 55 |
# File 'lib/trample/condition_proxy.rb', line 53 def within_eq(range) set(from_eq: range.first, to_eq: range.last) end |