Class: Spree::Admin::Tabs::Tab

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/admin/tabs/tab.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, label_translation_key, url, icon_key, partial_name, availability_checks, active_check, data_hook) ⇒ Tab

rubocop:disable Metrics/ParameterLists



7
8
9
10
11
12
13
14
15
16
# File 'app/models/spree/admin/tabs/tab.rb', line 7

def initialize(key, label_translation_key, url, icon_key, partial_name, availability_checks, active_check, data_hook) # rubocop:disable Metrics/ParameterLists
  @key = key
  @label_translation_key = label_translation_key
  @url = url
  @icon_key = icon_key
  @partial_name = partial_name
  @availability_checks = availability_checks
  @active_check = active_check
  @data_hook = data_hook
end

Instance Attribute Details

#data_hook ⇒ Object (readonly)

Returns the value of attribute data_hook.



5
6
7
# File 'app/models/spree/admin/tabs/tab.rb', line 5

def data_hook
  @data_hook
end

#icon_key ⇒ Object (readonly)

Returns the value of attribute icon_key.



5
6
7
# File 'app/models/spree/admin/tabs/tab.rb', line 5

def icon_key
  @icon_key
end

#key ⇒ Object (readonly)

Returns the value of attribute key.



5
6
7
# File 'app/models/spree/admin/tabs/tab.rb', line 5

def key
  @key
end

#label_translation_key ⇒ Object (readonly)

Returns the value of attribute label_translation_key.



5
6
7
# File 'app/models/spree/admin/tabs/tab.rb', line 5

def label_translation_key
  @label_translation_key
end

Instance Method Details

#active?(current_tab) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'app/models/spree/admin/tabs/tab.rb', line 30

def active?(current_tab)
  return false unless @active_check.present?

  @active_check.call(current_tab, @partial_name)
end

#available?(current_ability, resource) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
# File 'app/models/spree/admin/tabs/tab.rb', line 18

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

#url(resource = nil) ⇒ Object



26
27
28
# File 'app/models/spree/admin/tabs/tab.rb', line 26

def url(resource = nil)
  @url.is_a?(Proc) ? @url.call(resource) : @url
end