Class: FunctionalLightService::Organizer::Iterate

Inherits:
Object
  • Object
show all
Extended by:
ScopedReducable
Defined in:
lib/functional-light-service/organizer/iterate.rb

Constant Summary collapse

INFLECTOR =
Dry::Inflector.new

Class Method Summary collapse

Methods included from ScopedReducable

scoped_reduce

Class Method Details

.run(organizer, collection_key, steps) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/functional-light-service/organizer/iterate.rb', line 12

def self.run(organizer, collection_key, steps)
  # La singolarizzazione dipende solo dalla chiave: si calcola una volta,
  # non a ogni invocazione dello step (ne' tantomeno per ogni item)
  item_key = INFLECTOR.singularize(collection_key).to_sym

  ->(ctx) do
    return ctx if ctx.stop_processing?

    ctx[collection_key].each do |item|
      ctx[item_key] = item
      ctx = scoped_reduce(organizer, ctx, steps)
    end

    ctx
  end
end