module LightService::Orchestrator::ClassMethods
Public Instance Methods
execute(code_block)
click to toggle source
# File lib/light-service/orchestrator.rb, line 53 def execute(code_block) issue_deprecation_warning_for(__method__) lambda do |ctx| return ctx if ctx.stop_processing? ctx = code_block.call(ctx) ctx end end
iterate(collection_key, steps)
click to toggle source
# File lib/light-service/orchestrator.rb, line 64 def iterate(collection_key, steps) issue_deprecation_warning_for(__method__) lambda do |ctx| return ctx if ctx.stop_processing? collection = ctx[collection_key] item_key = collection_key.to_s.singularize.to_sym collection.each do |item| ctx[item_key] = item ctx = scoped_reduction(ctx, steps) end ctx end end
reduce(steps, context = @context)
click to toggle source
# File lib/light-service/orchestrator.rb, line 13 def reduce(steps, context = @context) issue_deprecation_warning_for(__method__) steps.each_with_object(context) do |step, ctx| if step.respond_to?(:call) step.call(ctx) elsif step.respond_to?(:execute) step.execute(ctx) else raise 'Pass either an action or organizer' end end end
reduce_if(condition_block, steps)
click to toggle source
# File lib/light-service/orchestrator.rb, line 42 def reduce_if(condition_block, steps) issue_deprecation_warning_for(__method__) lambda do |ctx| return ctx if ctx.stop_processing? ctx = scoped_reduction(ctx, steps) if condition_block.call(ctx) ctx end end
reduce_until(condition_block, steps)
click to toggle source
# File lib/light-service/orchestrator.rb, line 27 def reduce_until(condition_block, steps) issue_deprecation_warning_for(__method__) lambda do |ctx| return ctx if ctx.stop_processing? loop do ctx = scoped_reduction(ctx, steps) break if condition_block.call(ctx) || ctx.failure? end ctx end end
with(data = {})
click to toggle source
# File lib/light-service/orchestrator.rb, line 8 def with(data = {}) @context = LightService::Context.make(data) self end
with_callback(action, steps)
click to toggle source
# File lib/light-service/orchestrator.rb, line 81 def with_callback(action, steps) issue_deprecation_warning_for(__method__) lambda do |ctx| return ctx if ctx.stop_processing? # This will only allow 2 level deep nesting of callbacks previous_callback = ctx[:callback] ctx[:callback] = lambda do |context| reduce(steps, context) end ctx = action.execute(ctx) ctx[:callback] = previous_callback ctx end end
Private Instance Methods
issue_deprecation_warning_for(method_name)
click to toggle source
# File lib/light-service/orchestrator.rb, line 116 def issue_deprecation_warning_for(method_name) warning_msg = "`Orchestrator##{method_name}` is DEPRECATED and will be " \ "removed, please switch to `Organizer##{method_name} instead. " LightService::Deprecation.warn(warning_msg) end
scoped_reduction(ctx, steps)
click to toggle source
# File lib/light-service/orchestrator.rb, line 103 def scoped_reduction(ctx, steps) ctx.reset_skip_remaining! unless ctx.failure? ctx = if steps.is_a?(Array) reduce(steps, ctx) else reduce([steps], ctx) end ctx.reset_skip_remaining! unless ctx.failure? ctx end