Class: Katalyst::Navigation::Menu::Version

Inherits:
ApplicationRecord
  • Object
show all
Includes:
HasTree
Defined in:
app/models/katalyst/navigation/menu.rb

Instance Method Summary collapse

Methods included from HasTree

#tree

Instance Method Details

#itemsObject



117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'app/models/katalyst/navigation/menu.rb', line 117

def items
  # support building menus in memory
  # requires that items are added in order and index and depth are set
  return parent.items unless parent.persisted?

  items = parent.items.where(id: nodes.map(&:id)).index_by(&:id)
  nodes.map do |node|
    items[node.id]&.tap do |item|
      item.index = node.index
      item.depth = node.depth
    end
  end
end