Sha256: ee3e3f3e782969704389b1154c02ec8fb7ed8b7bc8144785f7c9ef8c6437bd3e

Contents?: true

Size: 967 Bytes

Versions: 1

Compression:

Stored size: 967 Bytes

Contents

# frozen_string_literal: true

module Jace
  # @api public
  # @author Darthjee
  #
  # Class responsible for dispatching the call of events
  class Dispatcher
    # @param before [Symbol,Proc,Array] all the methods / proc
    #   to be executed before block call
    # @param after [Symbol,Proc,Array] all the methods / proc
    #   to be executed after block call
    def initialize(before: [], after: [])
      @before = [before].flatten.compact
      @after = [after].flatten.compact
    end

    # Dispatch the event call on a context
    #
    # @param context [Object] Object where the procs / methods
    #   will be called on
    # @block [Proc] bloc to be performed between befores and afters
    #
    # @return [Object] result of block call
    def dispatch(context, &block)
      Executer.call(
        before: before,
        after: after,
        context: context,
        &block
      )
    end

    private

    attr_reader :before, :after
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jace-0.0.3 lib/jace/dispatcher.rb