Class: Refinery::MenuItem
- Inherits:
-
Object
- Object
- Refinery::MenuItem
- Defined in:
- lib/refinery/menu_item.rb
Instance Attribute Summary collapse
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#lft ⇒ Object
Returns the value of attribute lft.
-
#menu ⇒ Object
Returns the value of attribute menu.
-
#menu_match ⇒ Object
Returns the value of attribute menu_match.
-
#original_id ⇒ Object
Returns the value of attribute original_id.
-
#original_type ⇒ Object
Returns the value of attribute original_type.
-
#parent_id ⇒ Object
Returns the value of attribute parent_id.
-
#rgt ⇒ Object
Returns the value of attribute rgt.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #ancestors ⇒ Object
- #children ⇒ Object
- #descendants ⇒ Object
- #has_children? ⇒ Boolean (also: #has_descendants?)
- #has_parent? ⇒ Boolean
-
#initialize(menu, options = {}) ⇒ MenuItem
constructor
A new instance of MenuItem.
- #leaf? ⇒ Boolean
- #orphan? ⇒ Boolean
- #parent ⇒ Object
- #remap!(options) ⇒ Object
- #siblings ⇒ Object (also: #shown_siblings)
- #to_refinery_menu_item ⇒ Object
Constructor Details
#initialize(menu, options = {}) ⇒ MenuItem
Returns a new instance of MenuItem.
7 8 9 10 11 12 13 |
# File 'lib/refinery/menu_item.rb', line 7 def initialize(, = {}) @menu = remap!().each do |key, value| send "#{key}=", value end self.attributes = end |
Instance Attribute Details
#depth ⇒ Object
Returns the value of attribute depth.
4 5 6 |
# File 'lib/refinery/menu_item.rb', line 4 def depth @depth end |
#lft ⇒ Object
Returns the value of attribute lft.
4 5 6 |
# File 'lib/refinery/menu_item.rb', line 4 def lft @lft end |
#menu ⇒ Object
Returns the value of attribute menu.
4 5 6 |
# File 'lib/refinery/menu_item.rb', line 4 def @menu end |
#menu_match ⇒ Object
Returns the value of attribute menu_match.
4 5 6 |
# File 'lib/refinery/menu_item.rb', line 4 def @menu_match end |
#original_id ⇒ Object
Returns the value of attribute original_id.
4 5 6 |
# File 'lib/refinery/menu_item.rb', line 4 def original_id @original_id end |
#original_type ⇒ Object
Returns the value of attribute original_type.
4 5 6 |
# File 'lib/refinery/menu_item.rb', line 4 def original_type @original_type end |
#parent_id ⇒ Object
Returns the value of attribute parent_id.
4 5 6 |
# File 'lib/refinery/menu_item.rb', line 4 def parent_id @parent_id end |
#rgt ⇒ Object
Returns the value of attribute rgt.
4 5 6 |
# File 'lib/refinery/menu_item.rb', line 4 def rgt @rgt end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/refinery/menu_item.rb', line 4 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/refinery/menu_item.rb', line 4 def url @url end |
Instance Method Details
#ancestors ⇒ Object
21 22 23 |
# File 'lib/refinery/menu_item.rb', line 21 def ancestors @ancestors ||= generate_ancestors end |
#children ⇒ Object
25 26 27 |
# File 'lib/refinery/menu_item.rb', line 25 def children @children ||= generate_children end |
#descendants ⇒ Object
29 30 31 |
# File 'lib/refinery/menu_item.rb', line 29 def descendants @descendants ||= generate_descendants end |
#has_children? ⇒ Boolean Also known as: has_descendants?
33 34 35 |
# File 'lib/refinery/menu_item.rb', line 33 def has_children? !leaf? end |
#has_parent? ⇒ Boolean
38 39 40 |
# File 'lib/refinery/menu_item.rb', line 38 def has_parent? !orphan? end |
#leaf? ⇒ Boolean
46 47 48 |
# File 'lib/refinery/menu_item.rb', line 46 def leaf? @leaf ||= rgt.to_i - lft.to_i == 1 end |
#orphan? ⇒ Boolean
42 43 44 |
# File 'lib/refinery/menu_item.rb', line 42 def orphan? parent_id.nil? || .detect{ |item| compatible_with?(item) && item.original_id == parent_id}.nil? end |
#parent ⇒ Object
50 51 52 |
# File 'lib/refinery/menu_item.rb', line 50 def parent @parent ||= ancestors.detect { |item| item.original_id == parent_id } end |
#remap!(options) ⇒ Object
15 16 17 18 19 |
# File 'lib/refinery/menu_item.rb', line 15 def remap!() [:original_id] = .delete(:id) [:original_type] = .delete(:type) end |
#siblings ⇒ Object Also known as: shown_siblings
54 55 56 |
# File 'lib/refinery/menu_item.rb', line 54 def siblings @siblings ||= ((has_parent? ? parent.children : .roots) - [self]) end |
#to_refinery_menu_item ⇒ Object
59 60 61 |
# File 'lib/refinery/menu_item.rb', line 59 def attributes end |