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.
Constant Summary collapse
- NoMenuError =
Class.new(KeyError)
Instance Method Summary collapse
-
#add(menu_name, menu_item_options = {}) ⇒ Object
Add a new menu item to a menu in the collection.
-
#before_build(&block) ⇒ Object
Add callbacks that will be run before the menu is built.
- #clear! ⇒ Object
- #exists?(menu_name) ⇒ Boolean
- #fetch(menu_name) ⇒ Object
-
#initialize ⇒ MenuCollection
constructor
A new instance of MenuCollection.
- #menu(menu_name) {|menu| ... } ⇒ Object
-
#on_build(&block) ⇒ Object
Add callbacks that will be run when the menu is going to be built.
Constructor Details
#initialize ⇒ MenuCollection
Returns a new instance of MenuCollection.
11 12 13 14 15 |
# File 'lib/active_admin/menu_collection.rb', line 11 def initialize @menus = {} @build_callbacks = [] @built = false end |
Instance Method Details
#add(menu_name, menu_item_options = {}) ⇒ Object
Add a new menu item to a menu in the collection
18 19 20 21 22 |
# File 'lib/active_admin/menu_collection.rb', line 18 def add(, = {}) = find_or_create() .add end |
#before_build(&block) ⇒ Object
Add callbacks that will be run before the menu is built
50 51 52 |
# File 'lib/active_admin/menu_collection.rb', line 50 def before_build(&block) @build_callbacks.unshift(block) end |
#clear! ⇒ Object
24 25 26 27 |
# File 'lib/active_admin/menu_collection.rb', line 24 def clear! @menus = {} @built = false end |
#exists?(menu_name) ⇒ Boolean
29 30 31 |
# File 'lib/active_admin/menu_collection.rb', line 29 def exists?() @menus.keys.include? end |
#fetch(menu_name) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/active_admin/menu_collection.rb', line 33 def fetch() @menus[] or raise NoMenuError, "No menu by the name of #{.inspect} in availble menus: #{@menus.keys.join(", ")}" end |
#menu(menu_name) {|menu| ... } ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/active_admin/menu_collection.rb', line 54 def () = find_or_create() yield() if block_given? end |
#on_build(&block) ⇒ Object
Add callbacks that will be run when the menu is going to be built. This helps use with reloading and allows configurations to add items to menus.
45 46 47 |
# File 'lib/active_admin/menu_collection.rb', line 45 def on_build(&block) @build_callbacks << block end |