Class: Riak::MapReduce::Phase
- Inherits:
-
Object
- Object
- Riak::MapReduce::Phase
- Includes:
- Util::Translation
- Defined in:
- riak-client/lib/riak/map_reduce/phase.rb
Overview
Represents an individual phase in a map-reduce pipeline. Generally you’ll want to call methods of MapReduce instead of using this directly.
Instance Attribute Summary (collapse)
-
- (Array) arg
Any extra static arguments to pass to the phase.
-
- (String, ...) function
For :map and :reduce types, the Javascript function to run (as a string or hash with bucket/key), or the module + function in Erlang to run.
-
- (Boolean) keep
Whether results of this phase will be returned.
-
- (String) language
The language of the phase’s function - “javascript” or “erlang”.
-
- (Symbol) type
The type of phase - :map, :reduce, or :link.
Instance Method Summary (collapse)
-
- (Hash) as_json(options = nil)
Converts the phase to its JSON-compatible representation for job invocation.
-
- (Phase) initialize(options = {})
constructor
Creates a phase in the map-reduce pipeline.
-
- (String) to_json(*a)
Converts the phase to JSON for use while invoking a job.
Methods included from Util::Translation
Constructor Details
- (Phase) initialize(options = {})
Creates a phase in the map-reduce pipeline
47 48 49 50 51 52 53 |
# File 'riak-client/lib/riak/map_reduce/phase.rb', line 47 def initialize(={}) self.type = [:type] self.language = [:language] || "javascript" self.function = [:function] self.keep = [:keep] || false self.arg = [:arg] end |
Instance Attribute Details
- (Array) arg
Any extra static arguments to pass to the phase
38 39 40 |
# File 'riak-client/lib/riak/map_reduce/phase.rb', line 38 def arg @arg end |
- (String, ...) function
For :map and :reduce types, the Javascript function to run (as a string or hash with bucket/key), or the module + function in Erlang to run. For a :link type, a WalkSpec or an equivalent hash.
29 30 31 |
# File 'riak-client/lib/riak/map_reduce/phase.rb', line 29 def function @function end |
- (Boolean) keep
Whether results of this phase will be returned
35 36 37 |
# File 'riak-client/lib/riak/map_reduce/phase.rb', line 35 def keep @keep end |
- (String) language
The language of the phase’s function - “javascript” or “erlang”. Meaningless for :link type phases.
32 33 34 |
# File 'riak-client/lib/riak/map_reduce/phase.rb', line 32 def language @language end |
- (Symbol) type
The type of phase - :map, :reduce, or :link
26 27 28 |
# File 'riak-client/lib/riak/map_reduce/phase.rb', line 26 def type @type end |
Instance Method Details
- (Hash) as_json(options = nil)
Converts the phase to its JSON-compatible representation for job invocation.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'riak-client/lib/riak/map_reduce/phase.rb', line 86 def as_json(=nil) obj = case type when :map, :reduce defaults = {"language" => language, "keep" => keep} case function when Hash defaults.merge(function) when String if function =~ /\s*function/ defaults.merge("source" => function) else defaults.merge("name" => function) end when Array defaults.merge("module" => function[0], "function" => function[1]) end when :link spec = WalkSpec.normalize(function).first {"bucket" => spec.bucket, "tag" => spec.tag, "keep" => spec.keep || keep} end obj["arg"] = arg if arg { type => obj } end |
- (String) to_json(*a)
Converts the phase to JSON for use while invoking a job.
80 81 82 |
# File 'riak-client/lib/riak/map_reduce/phase.rb', line 80 def to_json(*a) as_json.to_json(*a) end |