Class: Refinery::MenuItem
- Inherits:
-
HashWithIndifferentAccess
- Object
- HashWithIndifferentAccess
- Refinery::MenuItem
- Defined in:
- lib/refinery/menu_item.rb
Instance Method Summary collapse
- #ancestors ⇒ Object
- #children ⇒ Object
- #descendants ⇒ Object
- #has_children? ⇒ Boolean (also: #has_descendants?)
- #has_parent? ⇒ Boolean
- #inspect ⇒ Object
- #menu ⇒ Object
- #parent ⇒ Object
- #siblings ⇒ Object (also: #shown_siblings)
Instance Method Details
#ancestors ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/refinery/menu_item.rb', line 16 def ancestors return @ancestors if @ancestors @ancestors = [] p = self @ancestors << p until(p = p.parent).nil? @ancestors end |
#children ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/refinery/menu_item.rb', line 25 def children @children ||= if has_children? .select{|item| item.type == type && item.parent_id == id} else [] end end |
#descendants ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/refinery/menu_item.rb', line 33 def descendants @descendants ||= if has_descendants? .select{|item| item.type == type && item.lft > lft && item.rgt < rgt} else [] end end |
#has_children? ⇒ Boolean Also known as: has_descendants?
41 42 43 |
# File 'lib/refinery/menu_item.rb', line 41 def has_children? @has_children ||= (rgt > lft + 1) end |
#has_parent? ⇒ Boolean
47 48 49 |
# File 'lib/refinery/menu_item.rb', line 47 def has_parent? !parent_id.nil? end |
#inspect ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/refinery/menu_item.rb', line 51 def inspect hash = {} ATTRIBUTES.each do |attribute| hash[attribute] = self[attribute] end hash end |
#menu ⇒ Object
61 62 63 |
# File 'lib/refinery/menu_item.rb', line 61 def ::Refinery.[] end |
#parent ⇒ Object
65 66 67 |
# File 'lib/refinery/menu_item.rb', line 65 def parent @parent ||= (.detect{|item| item.type == type && item.id == parent_id} if has_parent?) end |
#siblings ⇒ Object Also known as: shown_siblings
69 70 71 |
# File 'lib/refinery/menu_item.rb', line 69 def siblings @siblings ||= ((has_parent? ? children : .roots) - [self]) end |