Class: Yaso::StepBuilder

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

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ StepBuilder

Returns a new instance of StepBuilder.



11
12
13
# File 'lib/yaso/step_builder.rb', line 11

def initialize(klass)
  @klass = klass
end

Instance Method Details

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



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

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