Create store
# File lib/aruba/hooks.rb, line 12 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
# 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
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
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