Class: CouchProxy::Reduce::ReduceReducer

Inherits:
BaseReducer show all
Defined in:
lib/couchproxy/reduce/reduce_reducer.rb

Overview

Sorts and merges reduce query results from many different source streams.

Defined Under Namespace

Classes: NONE

Constant Summary collapse

KEY =
'key'.freeze
VALUE =
'value'.freeze
COUNT =
'_count'.freeze
SUM =
'_sum'.freeze
STATS =
'_stats'.freeze
BUILT_INS =
[COUNT, SUM, STATS]

Constants inherited from BaseReducer

BaseReducer::ID

Instance Method Summary collapse

Methods inherited from BaseReducer

#reduce

Constructor Details

#initialize(args) ⇒ ReduceReducer

Args should contain the following keys:

sources: List of stream sources used to identify from where
         streaming rows are arriving.
  limit: Maximum number of rows to return. If not specified, all
         rows are returned.
   skip: Number of rows at the start of the stream to skip before
         returning the rest. If not specified, no rows are skipped.

collator: A CouchProxy::Collator instance used to sort rows.

fn: The JavaScript reduce function to apply to the rows.

reducers: A block that, when called, returns a CouchProxy::Reducer

instance.


27
28
29
30
31
32
33
# File 'lib/couchproxy/reduce/reduce_reducer.rb', line 27

def initialize(args)
  @fn, @reducers, collator = args.values_at(:fn, :reducers, :collator)
  # key = 0, id = 1
  @sorter = proc {|a, b| collator.compare(a[0], b[0]) }
  @processes = []
  super(args)
end

Instance Method Details

#complete?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/couchproxy/reduce/reduce_reducer.rb', line 35

def complete?
  super && @processes.empty?
end