class 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
@para [Proc] block
The block which should be run for the hook
# File lib/aruba/hooks.rb, line 23 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
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 42 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 52 def exist?(label) store.key? label.to_sym end