Class: Decidim::MenuRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/decidim/menu_registry.rb

Overview

This class handles all logic regarding registering menus

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMenuRegistry

Returns a new instance of MenuRegistry.



61
62
63
# File 'lib/decidim/menu_registry.rb', line 61

def initialize
  @configurations = []
end

Instance Attribute Details

#configurationsObject (readonly)

Returns the value of attribute configurations.



59
60
61
# File 'lib/decidim/menu_registry.rb', line 59

def configurations
  @configurations
end

Class Method Details

.create(name) ⇒ Object

Creates an empty named menu

Parameters:

  • name (Symbol)

    The name of the menu



39
40
41
# File 'lib/decidim/menu_registry.rb', line 39

def create(name)
  all[name] = new
end

.destroy(name) ⇒ Object

Destroys a named menu

Parameters:

  • name (Symbol)

    The name of the menu



48
49
50
# File 'lib/decidim/menu_registry.rb', line 48

def destroy(name)
  all[name] = nil
end

.find(name) ⇒ Object

Finds a menu by name

Parameters:

  • name (Symbol)

    The name of the menu



30
31
32
# File 'lib/decidim/menu_registry.rb', line 30

def find(name)
  all[name]
end

.register(name, &block) ⇒ Object

Finds a menu by name or creates it if it does not exist. Optionally, registers a MenuItem DSL block for the menu.

Parameters:

  • name (Symbol)

    Name of the menu

  • &block (Menu)

    Registration body of the menu. It is stored to be evaluated at rendering time



17
18
19
20
21
22
23
# File 'lib/decidim/menu_registry.rb', line 17

def register(name, &block)
  menu = find(name) || create(name)

  menu.configurations << block

  menu
end