Class: Spree::Admin::MainMenu::Section

Inherits:
Object
  • Object
show all
Includes:
ItemManager
Defined in:
app/models/spree/admin/main_menu/section.rb

Direct Known Subclasses

Root

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ItemManager

#add, #child_with_key?, #insert_after, #insert_before, #item_for_key, #remove

Constructor Details

#initialize(key, label_translation_key, icon_key, availability_checks, items) ⇒ Section

Returns a new instance of Section.



9
10
11
12
13
14
15
# File 'app/models/spree/admin/main_menu/section.rb', line 9

def initialize(key, label_translation_key, icon_key, availability_checks, items)
  @key = key
  @label_translation_key = label_translation_key
  @icon_key = icon_key
  @availability_checks = availability_checks
  @items = items
end

Instance Attribute Details

#icon_key ⇒ Object (readonly)

Returns the value of attribute icon_key.



7
8
9
# File 'app/models/spree/admin/main_menu/section.rb', line 7

def icon_key
  @icon_key
end

#items ⇒ Object (readonly)

Returns the value of attribute items.



7
8
9
# File 'app/models/spree/admin/main_menu/section.rb', line 7

def items
  @items
end

#key ⇒ Object (readonly)

Returns the value of attribute key.



7
8
9
# File 'app/models/spree/admin/main_menu/section.rb', line 7

def key
  @key
end

#label_translation_key ⇒ Object (readonly)

Returns the value of attribute label_translation_key.



7
8
9
# File 'app/models/spree/admin/main_menu/section.rb', line 7

def label_translation_key
  @label_translation_key
end

Instance Method Details

#available?(current_ability, resource) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'app/models/spree/admin/main_menu/section.rb', line 17

def available?(current_ability, resource)
  return true if @availability_checks.empty?

  result = @availability_checks.map { |check| check.call(current_ability, resource) }

  result.all?(true)
end

#children? ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/models/spree/admin/main_menu/section.rb', line 25

def children?
  @items.any?
end