Class: ConvenientService::Service::Plugins::CanHaveBeforeStepCallbacks::Middleware

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

Instance Method Summary collapse

Instance Method Details

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

Examples:

Before CanHaveBeforeStepCallbacks usage.

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

  step :foo

  class self::Step
    before :result do |arguments|
      organizer.instance_exec(arguments) do |arguments|
        log("before :step")
      end
    end
  end

  def foo
    success
  end

  private

  def log(message)
    puts message
  end
end

After CanHaveBeforeStepCallbacks usage.

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

  step :foo

  before :step do |arguments|
    log("before :step")
  end

  def foo
    success
  end

  private

  def log(message)
    puts message
  end
end

Parameters:

  • method (Symbol)
  • block (Proc)

Returns:



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/convenient_service/service/plugins/can_have_before_step_callbacks/middleware.rb', line 63

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

  entity.step_class.class_exec(kwargs, block) do |kwargs, block|
    before :result, **kwargs.merge(source_location: block.source_location) do
      organizer.instance_exec(
        Support::Arguments.new(
          *args,
          **Utils::Hash.except(self.kwargs, [:organizer, :container])
        ),
        &block
      )
    end
  end
end