Class: ActiveAdmin::MenuCollection
- Inherits:
-
Object
- Object
- ActiveAdmin::MenuCollection
- Defined in:
- lib/active_admin/menu_collection.rb
Overview
A MenuCollection stores multiple menus for any given namespace. Namespaces delegate the addition of menu items to this class.
Instance Method Summary collapse
-
#add(menu_name, menu_item_options = {}) ⇒ Object
Add a new menu item to a menu in the collection.
- #build_default_menu ⇒ Object
- #built? ⇒ Boolean
- #clear! ⇒ Object
- #exists?(menu_name) ⇒ Boolean
- #fetch(menu_name) ⇒ Object
-
#initialize ⇒ MenuCollection
constructor
A new instance of MenuCollection.
- #menu(menu_name, &block) ⇒ Object
Constructor Details
#initialize ⇒ MenuCollection
Returns a new instance of MenuCollection.
8 9 10 |
# File 'lib/active_admin/menu_collection.rb', line 8 def initialize @menus = {} end |
Instance Method Details
#add(menu_name, menu_item_options = {}) ⇒ Object
Add a new menu item to a menu in the collection
13 14 15 |
# File 'lib/active_admin/menu_collection.rb', line 13 def add(, = {}) find_or_create().add() end |
#build_default_menu ⇒ Object
42 43 44 |
# File 'lib/active_admin/menu_collection.rb', line 42 def find_or_create DEFAULT_MENU end |
#built? ⇒ Boolean
38 39 40 |
# File 'lib/active_admin/menu_collection.rb', line 38 def built? @menus.present? end |
#clear! ⇒ Object
17 18 19 |
# File 'lib/active_admin/menu_collection.rb', line 17 def clear! @menus = {} end |
#exists?(menu_name) ⇒ Boolean
21 22 23 |
# File 'lib/active_admin/menu_collection.rb', line 21 def exists?() @menus.keys.include? end |
#fetch(menu_name) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/active_admin/menu_collection.rb', line 25 def fetch() unless built? @menus[] or raise NoMenuError, "No menu by the name of #{.inspect} in available menus: #{@menus.keys.join(", ")}" end |
#menu(menu_name, &block) ⇒ Object
32 33 34 35 36 |
# File 'lib/active_admin/menu_collection.rb', line 32 def (, &block) find_or_create().tap do || yield() if block_given? end end |