Class: Refinery::MenuItem

Inherits:
Object
  • Object
show all
Defined in:
core/lib/refinery/menu_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(menu, options = {}) ⇒ MenuItem

Returns a new instance of MenuItem



7
8
9
10
11
12
13
# File 'core/lib/refinery/menu_item.rb', line 7

def initialize(menu, options = {})
  @menu = menu
  remap!(options).each do |key, value|
    send "#{key}=", value
  end
  self.attributes = options
end

Instance Attribute Details

#depthObject

Returns the value of attribute depth



4
5
6
# File 'core/lib/refinery/menu_item.rb', line 4

def depth
  @depth
end

#lftObject

Returns the value of attribute lft



4
5
6
# File 'core/lib/refinery/menu_item.rb', line 4

def lft
  @lft
end

Returns the value of attribute menu



4
5
6
# File 'core/lib/refinery/menu_item.rb', line 4

def menu
  @menu
end

Returns the value of attribute menu_match



4
5
6
# File 'core/lib/refinery/menu_item.rb', line 4

def menu_match
  @menu_match
end

#original_idObject

Returns the value of attribute original_id



4
5
6
# File 'core/lib/refinery/menu_item.rb', line 4

def original_id
  @original_id
end

#original_typeObject

Returns the value of attribute original_type



4
5
6
# File 'core/lib/refinery/menu_item.rb', line 4

def original_type
  @original_type
end

#parent_idObject

Returns the value of attribute parent_id



4
5
6
# File 'core/lib/refinery/menu_item.rb', line 4

def parent_id
  @parent_id
end

#rgtObject

Returns the value of attribute rgt



4
5
6
# File 'core/lib/refinery/menu_item.rb', line 4

def rgt
  @rgt
end

#titleObject

Returns the value of attribute title



4
5
6
# File 'core/lib/refinery/menu_item.rb', line 4

def title
  @title
end

#urlObject

Returns the value of attribute url



4
5
6
# File 'core/lib/refinery/menu_item.rb', line 4

def url
  @url
end

Instance Method Details

#ancestorsObject



21
22
23
# File 'core/lib/refinery/menu_item.rb', line 21

def ancestors
  @ancestors ||= generate_ancestors
end

#childrenObject



25
26
27
# File 'core/lib/refinery/menu_item.rb', line 25

def children
  @children ||= generate_children
end

#descendantsObject



29
30
31
# File 'core/lib/refinery/menu_item.rb', line 29

def descendants
  @descendants ||= generate_descendants
end

#has_children?Boolean Also known as: has_descendants?

Returns:

  • (Boolean)


33
34
35
# File 'core/lib/refinery/menu_item.rb', line 33

def has_children?
  !leaf?
end

#has_parent?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'core/lib/refinery/menu_item.rb', line 38

def has_parent?
  !orphan?
end

#leaf?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'core/lib/refinery/menu_item.rb', line 46

def leaf?
  @leaf ||= rgt.to_i - lft.to_i == 1
end

#orphan?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'core/lib/refinery/menu_item.rb', line 42

def orphan?
  parent_id.nil? || menu.detect{ |item| compatible_with?(item) && item.original_id == parent_id}.nil?
end

#parentObject



50
51
52
# File 'core/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 'core/lib/refinery/menu_item.rb', line 15

def remap!(options)
  options[:original_id] = options.delete(:id)
  options[:original_type] = options.delete(:type)
  options
end

#siblingsObject Also known as: shown_siblings



54
55
56
# File 'core/lib/refinery/menu_item.rb', line 54

def siblings
  @siblings ||= ((has_parent? ? parent.children : menu.roots) - [self])
end

#to_refinery_menu_itemObject



59
60
61
# File 'core/lib/refinery/menu_item.rb', line 59

def to_refinery_menu_item
  attributes
end