Class: Riak::MapReduce::FilterBuilder

Inherits:
Object
  • Object
show all
Includes:
Util::Translation
Defined in:
lib/riak/map_reduce/filter_builder.rb

Overview

Builds key-filter lists for MapReduce inputs in a DSL-like fashion.

Constant Summary collapse

FILTERS =

Known filters available in riak_kv_mapred_filters, mapped to their arities. These are turned into instance methods. Example:

FilterBuilder.new do
  string_to_int
  less_than 50
end
{
  :int_to_string => 0,
  :string_to_int => 0,
  :float_to_string => 0,
  :string_to_float => 0,
  :to_upper => 0,
  :to_lower => 0,
  :tokenize => 2,
  :urldecode => 0,
  :greater_than => 1,
  :less_than => 1,
  :greater_than_eq => 1,
  :less_than_eq => 1,
  :between => [2, 3],
  :matches => 1,
  :neq => 1,
  :eq => 1,
  :set_member => -1,
  :similar_to => 2,
  :starts_with => 1,
  :ends_with => 1
}
LOGICAL_OPERATIONS =

Available logical operations for joining filter chains. These are turned into instance methods with leading underscores, with aliases to uppercase versions. Example:

FilterBuilder.new do
  string_to_int
  AND do
    greater_than_eq 50
    neq 100
  end
end
%w{and or not}

Instance Method Summary collapse

Methods included from Util::Translation

#i18n_scope, #t

Constructor Details

#initialize(&block) ⇒ FilterBuilder

Creates a new FilterBuilder. Pass a block that will be instance_eval’ed to construct the sequence of filters.



85
86
87
88
# File 'lib/riak/map_reduce/filter_builder.rb', line 85

def initialize(&block)
  @filters = []
  instance_eval(&block) if block_given?
end

Instance Method Details

#sequence(&block) ⇒ Object Also known as: seq

Wraps multi-step filters for use inside logical operations. Does not correspond to an actual filter.



92
93
94
# File 'lib/riak/map_reduce/filter_builder.rb', line 92

def sequence(&block)
  @filters << self.class.new(&block).to_a
end

#to_aObject

Returns A list of filters for handing to the MapReduce inputs.

Returns:

  • A list of filters for handing to the MapReduce inputs.



98
99
100
# File 'lib/riak/map_reduce/filter_builder.rb', line 98

def to_a
  @filters
end