Class: Riak::MapReduce::Phase
- Includes:
- Util::Translation
- Defined in:
- 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
-
#arg ⇒ Array
Any extra static arguments to pass to the phase.
-
#function ⇒ String, ...
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.
-
#keep ⇒ Boolean
Whether results of this phase will be returned.
-
#language ⇒ String
The language of the phase’s function - “javascript” or “erlang”.
-
#type ⇒ Symbol
The type of phase - :map, :reduce, or :link.
Instance Method Summary collapse
-
#as_json(options = nil) ⇒ Hash
Converts the phase to its JSON-compatible representation for job invocation.
-
#initialize(options = {}) ⇒ Phase
constructor
Creates a phase in the map-reduce pipeline.
-
#to_json(*a) ⇒ String
Converts the phase to JSON for use while invoking a job.
Methods included from Util::Translation
Constructor Details
#initialize(options = {}) ⇒ Phase
Creates a phase in the map-reduce pipeline
34 35 36 37 38 39 40 |
# File 'lib/riak/map_reduce/phase.rb', line 34 def initialize( = {}) self.type = [:type] self.language = [:language] || "javascript" self.function = [:function] self.keep = [:keep] || false self.arg = [:arg] end |
Instance Attribute Details
#arg ⇒ Array
Returns any extra static arguments to pass to the phase.
25 26 27 |
# File 'lib/riak/map_reduce/phase.rb', line 25 def arg @arg end |
#function ⇒ String, ...
Returns 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.
16 17 18 |
# File 'lib/riak/map_reduce/phase.rb', line 16 def function @function end |
#keep ⇒ Boolean
Returns whether results of this phase will be returned.
22 23 24 |
# File 'lib/riak/map_reduce/phase.rb', line 22 def keep @keep end |
#language ⇒ String
Returns the language of the phase’s function - “javascript” or “erlang”. Meaningless for :link type phases.
19 20 21 |
# File 'lib/riak/map_reduce/phase.rb', line 19 def language @language end |
#type ⇒ Symbol
Returns the type of phase - :map, :reduce, or :link.
13 14 15 |
# File 'lib/riak/map_reduce/phase.rb', line 13 def type @type end |
Instance Method Details
#as_json(options = nil) ⇒ Hash
Converts the phase to its JSON-compatible representation for job invocation.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/riak/map_reduce/phase.rb', line 73 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\s*\(/ || function =~ /\s*fun\s*\(.*\)\s*->/ 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 |
#to_json(*a) ⇒ String
Converts the phase to JSON for use while invoking a job.
67 68 69 |
# File 'lib/riak/map_reduce/phase.rb', line 67 def to_json(*a) as_json.to_json(*a) end |