Class: ActionNav::Item
- Inherits:
-
Object
- Object
- ActionNav::Item
- Defined in:
- lib/action_nav/item.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#count ⇒ Object
Returns the value of attribute count.
-
#description ⇒ Object
Returns the value of attribute description.
-
#hide_unless ⇒ Object
Returns the value of attribute hide_unless.
-
#icon ⇒ Object
Returns the value of attribute icon.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #add_child(id, &block) ⇒ Object
- #child(*ids) ⇒ Object
- #dsl(&block) ⇒ Object
-
#initialize(parent, id) ⇒ Item
constructor
A new instance of Item.
- #path ⇒ Object
Constructor Details
#initialize(parent, id) ⇒ Item
Returns a new instance of Item.
6 7 8 9 10 |
# File 'lib/action_nav/item.rb', line 6 def initialize(parent, id) @id = id @parent = parent @children = {} end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
13 14 15 |
# File 'lib/action_nav/item.rb', line 13 def children @children end |
#count ⇒ Object
Returns the value of attribute count.
19 20 21 |
# File 'lib/action_nav/item.rb', line 19 def count @count end |
#description ⇒ Object
Returns the value of attribute description.
16 17 18 |
# File 'lib/action_nav/item.rb', line 16 def description @description end |
#hide_unless ⇒ Object
Returns the value of attribute hide_unless.
18 19 20 |
# File 'lib/action_nav/item.rb', line 18 def hide_unless @hide_unless end |
#icon ⇒ Object
Returns the value of attribute icon.
17 18 19 |
# File 'lib/action_nav/item.rb', line 17 def icon @icon end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/action_nav/item.rb', line 12 def id @id end |
#title ⇒ Object
Returns the value of attribute title.
14 15 16 |
# File 'lib/action_nav/item.rb', line 14 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
15 16 17 |
# File 'lib/action_nav/item.rb', line 15 def url @url end |
Instance Method Details
#add_child(id, &block) ⇒ Object
25 26 27 28 29 |
# File 'lib/action_nav/item.rb', line 25 def add_child(id, &block) child_item = Item.new(self, id) block.call(child_item) if block_given? @children[id] = child_item end |
#child(*ids) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/action_nav/item.rb', line 31 def child(*ids) previous = self ids.each do |id| previous = previous.children[id] return nil if previous.nil? end previous end |
#dsl(&block) ⇒ Object
40 41 42 43 |
# File 'lib/action_nav/item.rb', line 40 def dsl(&block) ItemDSL.new(self).instance_eval(&block) self end |
#path ⇒ Object
21 22 23 |
# File 'lib/action_nav/item.rb', line 21 def path @parent ? [@parent.path, id].flatten : [id] end |