Class: Aruba::Hooks
- Inherits:
 - 
      Object
      
        
- Object
 - Aruba::Hooks
 
 
- Defined in:
 - lib/aruba/hooks.rb
 
Overview
Aruba Hooks
Instance Method Summary collapse
- 
  
    
      #append(label, block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Add new hook.
 - 
  
    
      #execute(label, context, *args)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Run hook.
 - 
  
    
      #exist?(label)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Check if hook exist.
 - 
  
    
      #initialize  ⇒ Hooks 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
Create store.
 
Constructor Details
#initialize ⇒ Hooks
Create store
      14 15 16  | 
    
      # File 'lib/aruba/hooks.rb', line 14 def initialize @store = {} end  | 
  
Instance Method Details
#append(label, block) ⇒ Object
Add new hook
      25 26 27 28 29 30  | 
    
      # File 'lib/aruba/hooks.rb', line 25 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) ⇒ Object
Run hook
      42 43 44 45 46  | 
    
      # 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) ⇒ Boolean
Check if hook exist
      52 53 54  | 
    
      # File 'lib/aruba/hooks.rb', line 52 def exist?(label) store.key? label.to_sym end  |