Class: PartialMenu::Menu
- Inherits:
-
Object
- Object
- PartialMenu::Menu
- Defined in:
- lib/partial_menu/menu.rb
Overview
Represents a menu with menu items
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
-
#active?(view) ⇒ Boolean
True if current url relates to any child menu item’s uri.
-
#initialize(props, layout = 'main', parent = nil) ⇒ Menu
constructor
rubocop:disable Metrics/MethodLength.
Constructor Details
#initialize(props, layout = 'main', parent = nil) ⇒ Menu
rubocop:disable Metrics/MethodLength
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/partial_menu/menu.rb', line 12 def initialize(props, layout = 'main', parent = nil) unless props.is_a? Array raise ::ArgumentError, "Expected an Array, got #{props.class}" end unless layout.is_a? String raise ::ArgumentError, "Expected a String, got #{layout.class}" end unless parent.nil? || (parent.is_a? PartialMenu::MenuItem) raise ::ArgumentError, "Expected MenuItem or nil, got #{parent.class}" end @props = props @layout = layout @items = [] @parent = parent set_id add_items(props) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/partial_menu/menu.rb', line 9 def id @id end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
7 8 9 |
# File 'lib/partial_menu/menu.rb', line 7 def items @items end |
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
6 7 8 |
# File 'lib/partial_menu/menu.rb', line 6 def layout @layout end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
8 9 10 |
# File 'lib/partial_menu/menu.rb', line 8 def parent @parent end |
Instance Method Details
#active?(view) ⇒ Boolean
True if current url relates to any child menu item’s uri
38 39 40 41 42 43 |
# File 'lib/partial_menu/menu.rb', line 38 def active?(view) @items.each do |item| return true if item.active?(view) end false end |