Class: Jrf::RowContext

Inherits:
Object
  • Object
show all
Defined in:
lib/jrf/row_context.rb

Constant Summary collapse

MISSING =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj = nil) ⇒ RowContext

Returns a new instance of RowContext.



27
28
29
30
31
# File 'lib/jrf/row_context.rb', line 27

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

Parameters:

  • value

    the value to set the attribute __jrf_current_stage to.



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
24
# 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],
      merge: spec[:merge],
      &spec.fetch(:step)
    )
  end
end

Instance Method Details

#_Object



39
40
41
# File 'lib/jrf/row_context.rb', line 39

def _
  @obj
end

#apply(collection = nil, &block) ⇒ Object

Raises:

  • (ArgumentError)


202
203
204
205
206
# File 'lib/jrf/row_context.rb', line 202

def apply(collection = nil, &block)
  raise ArgumentError, "apply requires a block" unless block

  @__jrf_current_stage.step_apply(collection || current_input, &block)
end

#flatObject



43
44
45
# File 'lib/jrf/row_context.rb', line 43

def flat
  Control::Flat.new(current_input)
end

#group_by(key, &block) ⇒ Object



208
209
210
211
# File 'lib/jrf/row_context.rb', line 208

def group_by(key, &block)
  block ||= proc { group }
  @__jrf_current_stage.step_group_by(key, &block)
end

#map(collection = nil, &block) ⇒ Object

Raises:

  • (ArgumentError)


190
191
192
193
194
# File 'lib/jrf/row_context.rb', line 190

def map(collection = nil, &block)
  raise ArgumentError, "map requires a block" unless block

  @__jrf_current_stage.step_map(:map, collection || current_input, &block)
end

#map_values(collection = nil, &block) ⇒ Object

Raises:

  • (ArgumentError)


196
197
198
199
200
# File 'lib/jrf/row_context.rb', line 196

def map_values(collection = nil, &block)
  raise ArgumentError, "map_values requires a block" unless block

  @__jrf_current_stage.step_map(:map_values, collection || current_input, &block)
end

#reduce(initial, &block) ⇒ Object

Raises:

  • (ArgumentError)


184
185
186
187
188
# File 'lib/jrf/row_context.rb', line 184

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



33
34
35
36
37
# File 'lib/jrf/row_context.rb', line 33

def reset(obj)
  @obj = obj
  @__jrf_current_input = obj
  self
end

#select(predicate) ⇒ Object



47
48
49
# File 'lib/jrf/row_context.rb', line 47

def select(predicate)
  predicate ? current_input : Control::DROPPED
end