Class: FunctionalLightService::Organizer::Iterate

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

Class Method Summary collapse

Methods included from ScopedReducable

scoped_reduce

Class Method Details

.run(organizer, collection_key, steps) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/functional-light-service/organizer/iterate.rb', line 8

def self.run(organizer, collection_key, steps)
  ->(ctx) do
    return ctx if ctx.stop_processing?

    collection = ctx[collection_key]
    inflector = Dry::Inflector.new
    item_key = inflector.singularize(collection_key).to_sym
    collection.each do |item|
      ctx[item_key] = item
      ctx = scoped_reduce(organizer, ctx, steps)
    end

    ctx
  end
end