Sha256: f5eabc3d69146ba51d825e43513eed9bc0b3aee06f1a2e1c7ce1734e60f975d3

Contents?: true

Size: 1.05 KB

Versions: 14

Compression:

Stored size: 1.05 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
    #
    # @param [Proc] block
    #   The block which should be run for the hook
    def append(label, block)
      unless store.key?(label.to_sym) && store[label.to_sym].respond_to?(:<<)
        store[label.to_sym] = []
      end
      store[label.to_sym] << block
    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

14 entries across 14 versions & 3 rubygems

Version Path
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/aruba-2.2.0/lib/aruba/hooks.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/aruba-2.2.0/lib/aruba/hooks.rb
aruba-2.2.0 lib/aruba/hooks.rb
aruba-2.1.0 lib/aruba/hooks.rb
aruba-2.0.1 lib/aruba/hooks.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/aruba-2.0.0/lib/aruba/hooks.rb
aruba-2.0.0 lib/aruba/hooks.rb
aruba-1.1.2 lib/aruba/hooks.rb
aruba-1.1.1 lib/aruba/hooks.rb
aruba-1.1.0 lib/aruba/hooks.rb
aruba-1.0.4 lib/aruba/hooks.rb
aruba-1.0.3 lib/aruba/hooks.rb
aruba-1.0.2 lib/aruba/hooks.rb
aruba-1.0.1 lib/aruba/hooks.rb