module ActiveAdmin::Menu::MenuNode

def [](id)

def [](id)
  @children[normalize_id(id)]
end

def []=(id, child)

def []=(id, child)
  @children[normalize_id(id)] = child
end

def _add(options)

If this ID is already taken, transfer the children of the existing item to the new item.
The method that actually adds new menu items. Called by the public method.
def _add(options)
  item = ActiveAdmin::MenuItem.new(options)
  item.send :children=, self[item.id].children if self[item.id]
  self[item.id] = item
end

def add(options)


menu.add parent: 'Dashboard', label: 'My Child Dashboard'
menu.add label: 'Dashboard'
menu = Menu.new
Example 2:

end
dash.add label: 'My Child Dashboard'
menu.add label: 'Dashboard' do |dash|
menu = Menu.new
Example 1:

as shown in the below examples. Both create an identical menu structure.
Recursively builds any given menu items. There are two syntaxes supported,
def add(options)
  parent_chain = Array.wrap(options.delete(:parent))
  item = if parent = parent_chain.shift
           options[:parent] = parent_chain if parent_chain.any?
           (self[parent] || add(label: parent)).add options
         else
           _add options.merge parent: self
         end
  yield(item) if block_given?
  item
end

def current?(item)

Used in the UI to visually distinguish which menu item is selected.
def current?(item)
  self == item || include?(item)
end

def include?(item)

Whether any children match the given item.
def include?(item)
  @children.values.include?(item) || @children.values.any? { |child| child.include?(item) }
end

def initialize

def initialize
  @children = {}
end

def items

def items
  @children.values
end

def normalize_id(id)

def normalize_id(id)
  case id
  when String, Symbol, ActiveModel::Name
    id.to_s.downcase.tr " ", "_"
  when ActiveAdmin::Resource::Name
    id.param_key
  else
    raise TypeError, "#{id.class} isn't supported as a Menu ID"
  end
end