class Aruba::Hooks

Aruba Hooks

Attributes

store[R]

Public Class Methods

new() click to toggle source

Create store

# File lib/aruba/hooks.rb, line 12
def initialize
  @store = {}
end

Public Instance Methods

append(label, block) click to toggle source

Add new hook

@param [String, Symbol] label

The name of the hook

@param [Proc] block

The block which should be run for the hook
# File lib/aruba/hooks.rb, line 23
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
execute(label, context, *args) click to toggle source

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
# File lib/aruba/hooks.rb, line 40
def execute(label, context, *args)
  Array(store[label.to_sym]).each do |block|
    context.instance_exec(*args, &block)
  end
end
exist?(label) click to toggle source

Check if hook exist

@param [String, Symbol] label

The name of the hook
# File lib/aruba/hooks.rb, line 50
def exist?(label)
  store.key? label.to_sym
end