Class: MenuMaker::Menu::MenuItem
- Inherits:
-
Object
- Object
- MenuMaker::Menu::MenuItem
show all
- Defined in:
- lib/menu_maker/menu.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(title, *paths, **options) ⇒ MenuItem
Returns a new instance of MenuItem.
79
80
81
82
83
|
# File 'lib/menu_maker/menu.rb', line 79
def initialize(title, *paths, **options)
@title = title
@paths = paths.map { |p| Path::Converter.convert(p) }
@options = options
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
111
112
113
|
# File 'lib/menu_maker/menu.rb', line 111
def method_missing(method, *args)
options && options[method] || ''
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
77
78
79
|
# File 'lib/menu_maker/menu.rb', line 77
def options
@options
end
|
Returns the value of attribute submenu.
85
86
87
|
# File 'lib/menu_maker/menu.rb', line 85
def
@submenu
end
|
#title ⇒ Object
Returns the value of attribute title.
77
78
79
|
# File 'lib/menu_maker/menu.rb', line 77
def title
@title
end
|
Instance Method Details
#all_paths ⇒ Object
103
104
105
|
# File 'lib/menu_maker/menu.rb', line 103
def all_paths
[*paths, *]
end
|
#has_path?(path) ⇒ Boolean
107
108
109
|
# File 'lib/menu_maker/menu.rb', line 107
def has_path?(path)
all_paths.include? Path::Converter.convert(path)
end
|
87
88
89
|
# File 'lib/menu_maker/menu.rb', line 87
def
!@submenu.nil?
end
|
#path ⇒ Object
119
120
121
|
# File 'lib/menu_maker/menu.rb', line 119
def path
@paths.first.path
end
|
#paths ⇒ Object
91
92
93
|
# File 'lib/menu_maker/menu.rb', line 91
def paths
@paths
end
|
123
124
125
|
# File 'lib/menu_maker/menu.rb', line 123
def
? .render : ''
end
|
#respond_to_missing?(method) ⇒ Boolean
115
116
117
|
# File 'lib/menu_maker/menu.rb', line 115
def respond_to_missing?(method)
!!(options && options[method])
end
|
95
96
97
98
99
100
101
|
# File 'lib/menu_maker/menu.rb', line 95
def
return [] unless
.items.reduce([]) do |all, item|
all + item.paths + item.
end.flatten
end
|
#to_s ⇒ Object
127
128
129
|
# File 'lib/menu_maker/menu.rb', line 127
def to_s
title
end
|