Class: Olivander::Menus::MenuItem

Inherits:
Object
  • Object
show all
Defined in:
lib/olivander/menus/menu_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hrefObject (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

#badgesObject



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_classObject



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

Returns:

  • (Boolean)


15
16
17
# File 'lib/olivander/menus/menu_item.rb', line 15

def module?
  @module
end


41
42
43
44
45
46
47
48
49
# File 'lib/olivander/menus/menu_item.rb', line 41

def submenu_items
  @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

#textObject



19
20
21
# File 'lib/olivander/menus/menu_item.rb', line 19

def text
  resolved_key(@key, "menus.#{@key}.text")
end

#visibleObject



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 with_submenu_items(&block)
  @submenu_items_blocks << block
  self
end