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 |
# File 'lib/jrf/row_context.rb', line 26 def initialize(obj = nil) @obj = obj @__jrf_current_stage = nil 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.allocate_reducer( spec.fetch(:value), initial: reducer_initial_value(spec.fetch(:initial)), finish: spec[:finish], &spec.fetch(:step) ) end end |
Instance Method Details
#_ ⇒ Object
36 37 38 |
# File 'lib/jrf/row_context.rb', line 36 def _ @obj end |
#flat ⇒ Object
40 41 42 |
# File 'lib/jrf/row_context.rb', line 40 def flat Control::Flat.new(@obj) end |
#group_by(key, &block) ⇒ Object
176 177 178 179 |
# File 'lib/jrf/row_context.rb', line 176 def group_by(key, &block) block ||= proc { group } @__jrf_current_stage.allocate_group_by(key, &block) end |
#map(&block) ⇒ Object
164 165 166 167 168 |
# File 'lib/jrf/row_context.rb', line 164 def map(&block) raise ArgumentError, "map requires a block" unless block @__jrf_current_stage.allocate_map(:array, @obj, &block) end |
#map_values(&block) ⇒ Object
170 171 172 173 174 |
# File 'lib/jrf/row_context.rb', line 170 def map_values(&block) raise ArgumentError, "map_values requires a block" unless block @__jrf_current_stage.allocate_map(:hash, @obj, &block) end |
#reduce(initial, &block) ⇒ Object
158 159 160 161 162 |
# File 'lib/jrf/row_context.rb', line 158 def reduce(initial, &block) raise ArgumentError, "reduce requires a block" unless block @__jrf_current_stage.allocate_reducer(@obj, initial: initial, &block) end |
#reset(obj) ⇒ Object
31 32 33 34 |
# File 'lib/jrf/row_context.rb', line 31 def reset(obj) @obj = obj self end |