Class: FunctionalLightService::Organizer::WithCallback

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

Class Method Summary collapse

Methods included from ScopedReducable

scoped_reduce

Class Method Details

.run(organizer, action, steps) ⇒ Object



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

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

    # This will only allow 2 level deep nesting of callbacks
    previous_callback = ctx[:callback]

    ctx[:callback] = ->(context) do
      ctx = scoped_reduce(organizer, context, steps)
      ctx
    end

    ctx = action.execute(ctx)
    ctx[:callback] = previous_callback

    ctx
  end
end