Class: MQ::Filter

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.

Yields:

  • block in FilterDSL context

Returns:

  • (String)


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_filterObject 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}")