Class: Jrf::RowContext
- Inherits:
-
Object
- Object
- Jrf::RowContext
- Defined in:
- lib/jrf/row_context.rb
Constant Summary collapse
- MISSING =
Object.new
Instance Attribute Summary collapse
-
#__jrf_current_stage ⇒ Object
writeonly
Sets the attribute __jrf_current_stage.
Class Method Summary collapse
Instance Method Summary collapse
- #_ ⇒ Object
- #flat ⇒ Object
- #group_by(key, &block) ⇒ Object
-
#initialize(obj = nil) ⇒ RowContext
constructor
A new instance of RowContext.
- #map(&block) ⇒ Object
- #map_values(&block) ⇒ Object
- #reduce(initial, &block) ⇒ Object
- #reset(obj) ⇒ Object
- #select(predicate) ⇒ Object
Constructor Details
#initialize(obj = nil) ⇒ RowContext
Returns a new instance of RowContext.
26 27 28 29 30 |
# File 'lib/jrf/row_context.rb', line 26 def initialize(obj = nil) @obj = obj @__jrf_current_stage = nil @__jrf_current_input = obj end |
Instance Attribute Details
#__jrf_current_stage=(value) ⇒ Object (writeonly)
Sets the attribute __jrf_current_stage
10 11 12 |
# File 'lib/jrf/row_context.rb', line 10 def __jrf_current_stage=(value) @__jrf_current_stage = value end |
Class Method Details
.define_reducer(name, &definition) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/jrf/row_context.rb', line 13 def define_reducer(name, &definition) define_method(name) do |*args, **kwargs, &block| spec = definition.call(self, *args, **kwargs, block: block) @__jrf_current_stage.step_reduce( spec.fetch(:value), initial: reducer_initial_value(spec.fetch(:initial)), finish: spec[:finish], &spec.fetch(:step) ) end end |
Instance Method Details
#_ ⇒ Object
38 39 40 |
# File 'lib/jrf/row_context.rb', line 38 def _ @obj end |
#flat ⇒ Object
42 43 44 |
# File 'lib/jrf/row_context.rb', line 42 def flat Control::Flat.new(current_input) end |
#group_by(key, &block) ⇒ Object
185 186 187 188 |
# File 'lib/jrf/row_context.rb', line 185 def group_by(key, &block) block ||= proc { group } @__jrf_current_stage.step_group_by(key, &block) end |
#map(&block) ⇒ Object
173 174 175 176 177 |
# File 'lib/jrf/row_context.rb', line 173 def map(&block) raise ArgumentError, "map requires a block" unless block @__jrf_current_stage.step_map(:map, @obj, &block) end |
#map_values(&block) ⇒ Object
179 180 181 182 183 |
# File 'lib/jrf/row_context.rb', line 179 def map_values(&block) raise ArgumentError, "map_values requires a block" unless block @__jrf_current_stage.step_map(:map_values, @obj, &block) end |
#reduce(initial, &block) ⇒ Object
167 168 169 170 171 |
# File 'lib/jrf/row_context.rb', line 167 def reduce(initial, &block) raise ArgumentError, "reduce requires a block" unless block @__jrf_current_stage.step_reduce(current_input, initial: initial, &block) end |
#reset(obj) ⇒ Object
32 33 34 35 36 |
# File 'lib/jrf/row_context.rb', line 32 def reset(obj) @obj = obj @__jrf_current_input = obj self end |