Class: Decidim::BlockRegistry
- Inherits:
 - 
      Object
      
        
- Object
 - Decidim::BlockRegistry
 
 
- Defined in:
 - lib/decidim/block_registry.rb
 
Overview
This class acts as a registry for any code blocks with names and should be used as a singleton through the ‘Decidim` core module. This allows registering code blocks for different use cases, for example for the authorization transfers.
Instance Method Summary collapse
- 
  
    
      #register(name) { ... } ⇒ Proc 
    
    
  
  
  
  
  
  
  
  
  
    
Register a code block with a name and the handler block.
 - 
  
    
      #registrations  ⇒ Hash<Symbol => Proc> 
    
    
  
  
  
  
  
  
  
  
  
    
Provides access to the registered blocks with their names.
 - #unregister(*names) ⇒ Object
 
Instance Method Details
#register(name) { ... } ⇒ Proc
Register a code block with a name and the handler block.
      22 23 24 25 26  | 
    
      # File 'lib/decidim/block_registry.rb', line 22 def register(name, &block) return unless block_given? registrations[name] = block end  | 
  
#registrations ⇒ Hash<Symbol => Proc>
Provides access to the registered blocks with their names.
      13 14 15  | 
    
      # File 'lib/decidim/block_registry.rb', line 13 def registrations @registrations ||= {} end  | 
  
#unregister(name) ⇒ Proc #unregister(*names) ⇒ Array<Proc>
      37 38 39 40 41 42 43 44  | 
    
      # File 'lib/decidim/block_registry.rb', line 37 def unregister(*names) blocks = names.map do |name| registrations.delete(name) end return blocks.first if names.length == 1 blocks end  |