Sha256: 096a0de62c5e5a8b8f52d2aa1aa7155df48de92acb2e98bd7f19eeab91c98af3

Contents?: true

Size: 679 Bytes

Versions: 2

Compression:

Stored size: 679 Bytes

Contents

module DispatchRider
  module Callbacks
    # Provides access for invoking callbacks.
    class Access
      attr_reader :callbacks

      def initialize(callbacks)
        @callbacks = callbacks
      end

      # Executes the passed block wrapped in the event's callbacks.
      # @param [Symbol] event
      # @param [Array] args
      # @param [Proc] block
      def invoke(event, *args, &block)
        stack_of_callbacks = callbacks.for(event).reverse

        block_with_callbacks = stack_of_callbacks.reduce(block) { |inner_block, outer_block|
          -> { outer_block.call(inner_block, *args) }
        }

        block_with_callbacks.call
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dispatch-rider-2.1.0 lib/dispatch-rider/callbacks/access.rb
dispatch-rider-2.0.0 lib/dispatch-rider/callbacks/access.rb