Class: ConvenientService::Service::Plugins::CanHaveAroundStepCallbacks::Middleware Private

Inherits:
MethodChainMiddleware
  • Object
show all
Defined in:
lib/convenient_service/service/plugins/can_have_around_step_callbacks/middleware.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

#next(method, **kwargs, &block) ⇒ ConvenientService::Common::Plugins::CanHaveCallbacks::Entities::Callback

Examples:

Before CanHaveAroundStepCallbacks usage.

class Service
  include ::ConvenientService::Standard::Config

  step :foo

  entity :Step do
    around :step do |chain, arguments|
      organizer.instance_exec(chain, arguments) do |chain, arguments|
        step = chain.yield

        log("around :step (#{step.index})")
      end
    end
  end

  def foo
    success
  end

  private

  def log(message)
    puts message
  end
end

After CanHaveAroundStepCallbacks usage.

class Service
  include ::ConvenientService::Standard::Config

  step :foo

  around :step do |chain, arguments|
    step = chain.yield

    log("after :step (#{step.index})")
  end

  def foo
    success
  end

  private

  def log(message)
    puts message
  end
end

Parameters:

  • method (Symbol)
  • block (Proc)

Returns:

Since:

  • 1.0.0



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/convenient_service/service/plugins/can_have_around_step_callbacks/middleware.rb', line 72

def next(method, **kwargs, &block)
  return chain.next(method, **kwargs, &block) if method != :step

  entity.step_class.class_exec(kwargs, block) do |kwargs, block|
    around :result, **kwargs.merge(source_location: block.source_location) do |chain|
      organizer.instance_exec(
        proc { chain.yield.step },
        params.to_callback_arguments,
        &block
      )
    end
  end
end