class Flows::SharedContextPipeline::Wrap

@api private

Constants

EMPTY_HASH
NODE_POSTPROCESSOR
NODE_PREPROCESSOR

Attributes

next_step[RW]

:reek: Attribute

router_def[R]
tracks_definitions[R]

Public Class Methods

new(method_name:, router_def:, &tracks_definitions) click to toggle source
# File lib/flows/shared_context_pipeline/wrap.rb, line 22
def initialize(method_name:, router_def:, &tracks_definitions)
  @method_name = method_name
  @router_def = router_def
  @tracks_definitions = tracks_definitions

  singleton_class.extend DSL::Tracks
  singleton_class.extend Result::Helpers

  singleton_class.instance_exec(&tracks_definitions)
end

Public Instance Methods

initialize_dup(other) click to toggle source

on `#dup` we're getting new empty singleton class so we need to initialize it like original one

# File lib/flows/shared_context_pipeline/wrap.rb, line 35
def initialize_dup(other)
  singleton_class.extend DSL::Tracks
  singleton_class.extend Result::Helpers
  singleton_class.instance_exec(&other.tracks_definitions)
end
name() click to toggle source
# File lib/flows/shared_context_pipeline/wrap.rb, line 41
def name
  singleton_class.tracks.first_step_name
end
to_node(method_source) click to toggle source
# File lib/flows/shared_context_pipeline/wrap.rb, line 45
def to_node(method_source)
  Flows::Flow::Node.new(
    body: make_body(method_source),
    router: router_def.to_router(next_step),
    meta: { wrap_name: @method_name },
    preprocessor: NODE_PREPROCESSOR,
    postprocessor: NODE_POSTPROCESSOR
  )
end

Private Instance Methods

make_body(method_source) click to toggle source
# File lib/flows/shared_context_pipeline/wrap.rb, line 61
def make_body(method_source)
  flow = make_flow(method_source)
  wrapper = method_source.method(@method_name)

  lambda do |context|
    wrapper.call(context[:data], context[:meta]) do
      flow.call(nil, context: context)
    end
  end
end
make_flow(method_source) click to toggle source
# File lib/flows/shared_context_pipeline/wrap.rb, line 57
def make_flow(method_source)
  singleton_class.tracks.to_flow(method_source)
end