Sha256: a6e3824809c46638ef9e143eaccbd56dd764976b86cef6fa598277c0f9daf491

Contents?: true

Size: 1.09 KB

Versions: 26

Compression:

Stored size: 1.09 KB

Contents

# Aruba
module Aruba
  # Aruba Hooks
  class Hooks
    private

    attr_reader :store

    public

    # Create store
    def initialize
      @store = {}
    end

    # Add new hook
    #
    # @param [String, Symbol] label
    #   The name of the hook
    #
    # @para [Proc] block
    #   The block which should be run for the hook
    def append(label, block)
      if store.key?(label.to_sym) && store[label.to_sym].respond_to?(:<<)
        store[label.to_sym] << block
      else
        store[label.to_sym] = []
        store[label.to_sym] << block
      end
    end

    # Run hook
    #
    # @param [String, Symbol] label
    #   The name of the hook
    #
    # @param [Object] context
    #   The context in which the hook is run
    #
    # @param [Array] args
    #   Other arguments
    def execute(label, context, *args)
      Array(store[label.to_sym]).each do |block|
        context.instance_exec(*args, &block)
      end
    end

    # Check if hook exist
    #
    # @param [String, Symbol] label
    #   The name of the hook
    def exist?(label)
      store.key? label.to_sym
    end
  end
end

Version data entries

26 entries across 26 versions & 3 rubygems

Version Path
aruba-0.14.14 lib/aruba/hooks.rb
aruba-0.14.13 lib/aruba/hooks.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/aruba-0.14.12/lib/aruba/hooks.rb
aruba-0.14.12 lib/aruba/hooks.rb
aruba-0.14.11 lib/aruba/hooks.rb
aruba-0.14.10 lib/aruba/hooks.rb
aruba-0.14.9 lib/aruba/hooks.rb
aruba-0.14.8 lib/aruba/hooks.rb
aruba-0.14.7 lib/aruba/hooks.rb
aruba-0.14.6 lib/aruba/hooks.rb
aruba-0.14.5 lib/aruba/hooks.rb
aruba-0.14.4 lib/aruba/hooks.rb
aruba-0.14.3 lib/aruba/hooks.rb
aruba-1.0.0.pre.alpha.2 lib/aruba/hooks.rb
aruba-1.0.0.pre.alpha.1 lib/aruba/hooks.rb
aruba-win-fix-0.14.2 lib/aruba/hooks.rb
aruba-0.14.2 lib/aruba/hooks.rb
aruba-0.14.1 lib/aruba/hooks.rb
aruba-0.14.0 lib/aruba/hooks.rb
aruba-0.13.0 lib/aruba/hooks.rb