Class: Jrf::RowContext
- Inherits:
-
Object
- Object
- Jrf::RowContext
- Defined in:
- lib/jrf/row_context.rb
Defined Under Namespace
Classes: ReducerToken
Constant Summary collapse
- MISSING =
Object.new
Class Method Summary collapse
Instance Method Summary collapse
- #_ ⇒ Object
- #__jrf_begin_stage__(stage, probing: false) ⇒ Object
- #__jrf_reducer_called? ⇒ Boolean
- #flat ⇒ Object
-
#initialize(obj = nil) ⇒ RowContext
constructor
A new instance of RowContext.
- #reduce(initial, &block) ⇒ Object
- #reset(obj) ⇒ Object
Constructor Details
#initialize(obj = nil) ⇒ RowContext
Returns a new instance of RowContext.
25 26 27 28 |
# File 'lib/jrf/row_context.rb', line 25 def initialize(obj = nil) @obj = obj @__jrf_stage = nil end |
Class Method Details
.define_reducer(name, &definition) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/jrf/row_context.rb', line 11 def define_reducer(name, &definition) define_method(name) do |*args, **kwargs, &block| spec = definition.call(self, *args, **kwargs, block: block) create_reducer( spec.fetch(:value), initial: reducer_initial_value(spec.fetch(:initial)), finish: spec[:finish], emit_many: spec.fetch(:emit_many, false), &spec.fetch(:step) ) end end |
Instance Method Details
#_ ⇒ Object
35 36 37 |
# File 'lib/jrf/row_context.rb', line 35 def _ @obj end |
#__jrf_begin_stage__(stage, probing: false) ⇒ Object
152 153 154 155 156 157 |
# File 'lib/jrf/row_context.rb', line 152 def __jrf_begin_stage__(stage, probing: false) @__jrf_stage = stage stage[:reducer_cursor] = 0 stage[:reducer_called] = false stage[:reducer_probing] = probing end |
#__jrf_reducer_called? ⇒ Boolean
159 160 161 |
# File 'lib/jrf/row_context.rb', line 159 def __jrf_reducer_called? @__jrf_stage && @__jrf_stage[:reducer_called] end |
#flat ⇒ Object
39 40 41 |
# File 'lib/jrf/row_context.rb', line 39 def flat Control::Flat.new(@obj) end |
#reduce(initial, &block) ⇒ Object
146 147 148 149 150 |
# File 'lib/jrf/row_context.rb', line 146 def reduce(initial, &block) raise ArgumentError, "reduce requires a block" unless block create_reducer(@obj, initial: initial, &block) end |
#reset(obj) ⇒ Object
30 31 32 33 |
# File 'lib/jrf/row_context.rb', line 30 def reset(obj) @obj = obj self end |