Class: RQuery::OperationCollector
- Inherits:
-
Object
- Object
- RQuery::OperationCollector
- Defined in:
- lib/rquery/operation_collector.rb
Constant Summary collapse
- NOT_PREFIX =
'not_'
- NIL_PREFIX =
''
Instance Method Summary collapse
-
#&(second) ⇒ Object
used to group operations for anding on a single line example with sqlite adapter (user.age.in [1,2,3]) | (user.name.contains “foo”) =>(age in (?) and name like ‘%’ || ‘foo’ || ‘%’).
-
#add_operation(val) ⇒ Object
add and operation to the @operations array which will be popped and pushed depending on the operations sequence and arrangement.
- #between(*args) ⇒ Object (also: #from)
- #contains(str) ⇒ Object
- #in(*args) ⇒ Object
-
#initialize ⇒ OperationCollector
constructor
A new instance of OperationCollector.
- #not=(arg) ⇒ Object
- #not_between(*args) ⇒ Object (also: #not_from)
- #not_in(*args) ⇒ Object
-
#to_conditions ⇒ Object
return a conditions array for use with ActiveRecord.find.
- #to_s ⇒ Object
- #without(str) ⇒ Object
- #|(second) ⇒ Object
Constructor Details
#initialize ⇒ OperationCollector
Returns a new instance of OperationCollector.
6 7 8 9 10 |
# File 'lib/rquery/operation_collector.rb', line 6 def initialize # @name, @prefix = optns[:name], optns[:prefix] @operations = [] @values = [] end |
Instance Method Details
#&(second) ⇒ Object
used to group operations for anding on a single line example with sqlite adapter (user.age.in [1,2,3]) | (user.name.contains “foo”)
>(age in (?) and name like ‘%’ || ‘foo’ || ‘%’)
note that second is not used in this case because it should have been collected into the @operations array earlier
35 36 37 38 |
# File 'lib/rquery/operation_collector.rb', line 35 def &(second) @operations << AndOperationsGroup.new(tail_ops!(2)) self end |
#add_operation(val) ⇒ Object
add and operation to the @operations array which will be popped and pushed depending on the operations sequence and arrangement
23 24 25 26 |
# File 'lib/rquery/operation_collector.rb', line 23 def add_operation(val) @operations << val.to_s self end |
#between(*args) ⇒ Object Also known as: from
53 54 55 |
# File 'lib/rquery/operation_collector.rb', line 53 def between(*args) call_between(NIL_PREFIX, *args) end |
#contains(str) ⇒ Object
61 62 63 64 |
# File 'lib/rquery/operation_collector.rb', line 61 def contains(str) @values << str chain :contains end |
#in(*args) ⇒ Object
45 46 47 |
# File 'lib/rquery/operation_collector.rb', line 45 def in(*args) call_in(NIL_PREFIX, *args) end |
#not=(arg) ⇒ Object
71 72 73 74 |
# File 'lib/rquery/operation_collector.rb', line 71 def not=(arg) @values << arg chain :neq end |
#not_between(*args) ⇒ Object Also known as: not_from
57 58 59 |
# File 'lib/rquery/operation_collector.rb', line 57 def not_between(*args) call_between(NOT_PREFIX, *args) end |
#not_in(*args) ⇒ Object
49 50 51 |
# File 'lib/rquery/operation_collector.rb', line 49 def not_in(*args) call_in(NOT_PREFIX, *args) end |
#to_conditions ⇒ Object
return a conditions array for use with ActiveRecord.find
17 18 19 |
# File 'lib/rquery/operation_collector.rb', line 17 def to_conditions [to_s] + @values end |
#to_s ⇒ Object
12 13 14 |
# File 'lib/rquery/operation_collector.rb', line 12 def to_s RQuery::Config.adapter.join(@operations) end |
#without(str) ⇒ Object
66 67 68 69 |
# File 'lib/rquery/operation_collector.rb', line 66 def without(str) @values << str chain :without end |
#|(second) ⇒ Object
40 41 42 43 |
# File 'lib/rquery/operation_collector.rb', line 40 def |(second) @operations << OrOperationsGroup.new(tail_ops!(2)) self end |