Class: Spree::Admin::Tabs::TabBuilder

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

Instance Method Summary collapse

Methods included from PermissionChecks

#with_admin_ability_check, #with_availability_check, #with_create_ability_check, #with_fire_ability_check, #with_index_ability_check, #with_manage_ability_check, #with_resend_ability_check, #with_state_change_check, #with_update_ability_check

Constructor Details

#initialize(key, url) ⇒ TabBuilder

Returns a new instance of TabBuilder.



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

def initialize(key, url)
  @key = key
  @label_translation_key = key
  @url = url
  @icon_key = nil
  @partial_name = key
  @availability_checks = []
  @active_check = nil
  @data_hook = nil
end

Instance Method Details

#build ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/spree/admin/tabs/tab_builder.rb', line 48

def build
  Tab.new(
    @key,
    @label_translation_key,
    @url,
    @icon_key,
    @partial_name,
    @availability_checks,
    @active_check,
    @data_hook
  )
end

#with_active_check ⇒ Object



33
34
35
36
# File 'app/models/spree/admin/tabs/tab_builder.rb', line 33

def with_active_check
  @active_check = ->(current_tab, partial_name) { current_tab.to_s == partial_name.to_s }
  self
end

#with_completed_check ⇒ Object



38
39
40
41
# File 'app/models/spree/admin/tabs/tab_builder.rb', line 38

def with_completed_check
  @availability_checks << ->(_current_ability, resource) { resource.completed? }
  self
end

#with_data_hook(data_hook) ⇒ Object



43
44
45
46
# File 'app/models/spree/admin/tabs/tab_builder.rb', line 43

def with_data_hook(data_hook)
  @data_hook = data_hook
  self
end

#with_icon_key(icon_key) ⇒ Object



23
24
25
26
# File 'app/models/spree/admin/tabs/tab_builder.rb', line 23

def with_icon_key(icon_key)
  @icon_key = icon_key
  self
end

#with_label_translation_key(key) ⇒ Object



18
19
20
21
# File 'app/models/spree/admin/tabs/tab_builder.rb', line 18

def with_label_translation_key(key)
  @label_translation_key = key
  self
end

#with_partial_name(partial_name) ⇒ Object



28
29
30
31
# File 'app/models/spree/admin/tabs/tab_builder.rb', line 28

def with_partial_name(partial_name)
  @partial_name = partial_name
  self
end