Class: Yaso::Logic::StepBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/yaso/logic/step_builder.rb

Constant Summary collapse

CATEGORIES =
{
  step: Step,
  pass: Pass,
  failure: Failure,
  wrap: Wrap,
  switch: Switch
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ StepBuilder

Returns a new instance of StepBuilder.



14
15
16
# File 'lib/yaso/logic/step_builder.rb', line 14

def initialize(klass)
  @klass = klass
end

Instance Method Details

#call(object:, category:, block:, **opts) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/yaso/logic/step_builder.rb', line 18

def call(object:, category:, block:, **opts)
  logic_class = CATEGORIES[category]
  invocable_type, invocable = Invocable.call(object, with_block: logic_class == Wrap, **opts)
  if invocable_type == Invocable::METHOD
    opts[:name] = logic_class == Switch ? build_switch(object, **opts, &block) : build_method(object, &block)
  end
  opts[:wrapper] = build_wrapper(&block) if logic_class == Wrap
  logic_class.new(invocable: invocable, **opts)
end