Class: MQ::Filter
- Inherits:
-
Object
- Object
- MQ::Filter
- Defined in:
- lib/mq/query.rb
Overview
Represents a boolean filter expression for use inside select() and map().
Filters can be combined with & (and) and | (or):
contains("foo") & starts_with("bar")
# => 'contains("foo") and starts_with("bar")'
Class Method Summary collapse
-
.build { ... } ⇒ String
Build a filter expression by evaluating a block in FilterDSL context.
Instance Method Summary collapse
-
#&(other) ⇒ Object
Combine two filters with boolean AND.
-
#initialize(expr) ⇒ Filter
constructor
A new instance of Filter.
- #to_filter ⇒ Object (also: #to_query, #to_s)
-
#|(other) ⇒ Object
Combine two filters with boolean OR.
Constructor Details
#initialize(expr) ⇒ Filter
Returns a new instance of Filter.
479 480 481 |
# File 'lib/mq/query.rb', line 479 def initialize(expr) @expr = expr.to_s end |
Class Method Details
.build { ... } ⇒ String
Build a filter expression by evaluating a block in MQ::FilterDSL context.
486 487 488 489 |
# File 'lib/mq/query.rb', line 486 def self.build(&block) result = FilterDSL.new.instance_eval(&block) result.respond_to?(:to_filter) ? result.to_filter : result.to_s end |
Instance Method Details
#&(other) ⇒ Object
Combine two filters with boolean AND.
492 |
# File 'lib/mq/query.rb', line 492 def &(other) = self.class.new("#{@expr} and #{other}") |
#to_filter ⇒ Object Also known as: to_query, to_s
497 |
# File 'lib/mq/query.rb', line 497 def to_filter = @expr |
#|(other) ⇒ Object
Combine two filters with boolean OR.
495 |
# File 'lib/mq/query.rb', line 495 def |(other) = self.class.new("#{@expr} or #{other}") |