Sha256: ce9767e078c2eb6e1d4b5a51a7c8dff753b4c2ef831668d353edf8e4bc9025cd

Contents?: true

Size: 1.16 KB

Versions: 7

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Common
    module Plugins
      module HasCallbacks
        class Middleware < Core::MethodChainMiddleware
          def next(*args, **kwargs, &block)
            ##
            # class Service
            #   before :result do
            #   end
            #
            #   before :result do |arguments|
            #   end
            # end
            #
            entity.callbacks.for([:before, method]).each { |callback| callback.call_in_context_with_arguments(entity, *args, **kwargs, &block) }

            original_value = chain.next(*args, **kwargs, &block)

            ##
            # class Service
            #   after :result do
            #   end
            #
            #   after :result do |result|
            #   end
            #
            #   after :result do |result, arguments|
            #   end
            # end
            #
            entity.callbacks.for([:after, method]).reverse_each { |callback| callback.call_in_context_with_value_and_arguments(entity, original_value, *args, **kwargs, &block) }

            original_value
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
convenient_service-0.12.0 lib/convenient_service/common/plugins/has_callbacks/middleware.rb
convenient_service-0.11.0 lib/convenient_service/common/plugins/has_callbacks/middleware.rb
convenient_service-0.10.1 lib/convenient_service/common/plugins/has_callbacks/middleware.rb
convenient_service-0.10.0 lib/convenient_service/common/plugins/has_callbacks/middleware.rb
convenient_service-0.9.0 lib/convenient_service/common/plugins/has_callbacks/middleware.rb
convenient_service-0.8.0 lib/convenient_service/common/plugins/has_callbacks/middleware.rb
convenient_service-0.7.0 lib/convenient_service/common/plugins/has_callbacks/middleware.rb