Class: Olivander::Menus::MenuItem
- Inherits:
-
Object
- Object
- Olivander::Menus::MenuItem
- Defined in:
- lib/olivander/menus/menu_item.rb
Instance Attribute Summary collapse
-
#href ⇒ Object
readonly
Returns the value of attribute href.
Instance Method Summary collapse
- #badges ⇒ Object
- #icon_class ⇒ Object
-
#initialize(key, href = nil, icon = nil, is_module: false) ⇒ MenuItem
constructor
A new instance of MenuItem.
- #module? ⇒ Boolean
- #submenu_items ⇒ Object
- #text ⇒ Object
- #visible ⇒ Object
- #with_badges(&block) ⇒ Object
- #with_condition(&block) ⇒ Object
- #with_submenu_items(&block) ⇒ Object
Constructor Details
#initialize(key, href = nil, icon = nil, is_module: false) ⇒ MenuItem
Returns a new instance of MenuItem.
6 7 8 9 10 11 12 13 |
# File 'lib/olivander/menus/menu_item.rb', line 6 def initialize(key, href = nil, icon = nil, is_module: false) @key = key @href = href @icon = icon @submenu_items_blocks = [] @badges_blocks = [] @module = is_module end |
Instance Attribute Details
#href ⇒ Object (readonly)
Returns the value of attribute href.
4 5 6 |
# File 'lib/olivander/menus/menu_item.rb', line 4 def href @href end |
Instance Method Details
#badges ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/olivander/menus/menu_item.rb', line 56 def badges @badges ||= [].tap do |arr| if visible @badges_blocks.each do |block| block.call.each { |badge| arr << badge } end end end end |
#icon_class ⇒ Object
23 24 25 |
# File 'lib/olivander/menus/menu_item.rb', line 23 def icon_class @icon || resolved_key(@key, "menus.#{@key}.icon", 'menus.default_icon') end |
#module? ⇒ Boolean
15 16 17 |
# File 'lib/olivander/menus/menu_item.rb', line 15 def module? @module end |
#submenu_items ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/olivander/menus/menu_item.rb', line 41 def @submenu_items ||= [].tap do |arr| if visible @submenu_items_blocks.each do |block| block.call.each { |item| arr << item if item.visible } end end end end |
#text ⇒ Object
19 20 21 |
# File 'lib/olivander/menus/menu_item.rb', line 19 def text resolved_key(@key, "menus.#{@key}.text") end |
#visible ⇒ Object
27 28 29 |
# File 'lib/olivander/menus/menu_item.rb', line 27 def visible @visible ||= evaluate_conditions_block end |
#with_badges(&block) ⇒ Object
51 52 53 54 |
# File 'lib/olivander/menus/menu_item.rb', line 51 def with_badges(&block) @badges_blocks << block self end |
#with_condition(&block) ⇒ Object
31 32 33 34 |
# File 'lib/olivander/menus/menu_item.rb', line 31 def with_condition(&block) @conditions_block = block self end |
#with_submenu_items(&block) ⇒ Object
36 37 38 39 |
# File 'lib/olivander/menus/menu_item.rb', line 36 def (&block) @submenu_items_blocks << block self end |