Module: Paratrooper::Callbacks
- Included in:
- Configuration
- Defined in:
- lib/paratrooper/callbacks.rb
Instance Method Summary collapse
-
#add_callback(name, &block) ⇒ Object
Public: Add misc.
- #build_callback(name, context = nil, &block) ⇒ Object
- #callbacks ⇒ Object
Instance Method Details
#add_callback(name, &block) ⇒ Object
Public: Add misc. function to be called at a later time
name - String name of callback
Example: before_[method_name], after_[method_name]
block - Code to be executed during callback
9 10 11 |
# File 'lib/paratrooper/callbacks.rb', line 9 def add_callback(name, &block) callbacks[name] << block end |
#build_callback(name, context = nil, &block) ⇒ Object
17 18 19 20 21 |
# File 'lib/paratrooper/callbacks.rb', line 17 def build_callback(name, context = nil, &block) execute_callback("before_#{name}".to_sym, context) block.call if block_given? execute_callback("after_#{name}".to_sym, context) end |
#callbacks ⇒ Object
13 14 15 |
# File 'lib/paratrooper/callbacks.rb', line 13 def callbacks @callbacks ||= Hash.new { |hash, key| hash[key] = [] } end |