Sha256: 6b43907dc4fcc59f084fad58a0a682e848fd516ea618f824feeb0f06a8329dfd

Contents?: true

Size: 680 Bytes

Versions: 18

Compression:

Stored size: 680 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

18 entries across 18 versions & 1 rubygems

Version Path
dispatch-rider-1.9.0 lib/dispatch-rider/callbacks/access.rb
dispatch-rider-1.8.6 lib/dispatch-rider/callbacks/access.rb
dispatch-rider-1.8.5 lib/dispatch-rider/callbacks/access.rb
dispatch-rider-1.8.4 lib/dispatch-rider/callbacks/access.rb
dispatch-rider-1.8.3 lib/dispatch-rider/callbacks/access.rb
dispatch-rider-1.8.2 lib/dispatch-rider/callbacks/access.rb
dispatch-rider-1.8.1 lib/dispatch-rider/callbacks/access.rb
dispatch-rider-1.8.0 lib/dispatch-rider/callbacks/access.rb
dispatch-rider-1.7.2 lib/dispatch-rider/callbacks/access.rb
dispatch-rider-1.7.1 lib/dispatch-rider/callbacks/access.rb
dispatch-rider-1.7.0 lib/dispatch-rider/callbacks/access.rb
dispatch-rider-1.6.2 lib/dispatch-rider/callbacks/access.rb
dispatch-rider-1.6.1 lib/dispatch-rider/callbacks/access.rb
dispatch-rider-1.6.0 lib/dispatch-rider/callbacks/access.rb
dispatch-rider-1.5.3 lib/dispatch-rider/callbacks/access.rb
dispatch-rider-1.5.2 lib/dispatch-rider/callbacks/access.rb
dispatch-rider-1.5.1 lib/dispatch-rider/callbacks/access.rb
dispatch-rider-1.5.0 lib/dispatch-rider/callbacks/access.rb