Class: CardNavBuilder

Inherits:
Object show all
Includes:
ActionView::Helpers::TagHelper, SvgIconHelper
Defined in:
app/helpers/card_nav_builder.rb

Instance Method Summary collapse

Methods included from SvgIconHelper

#fetch_svg_icon, #svg_icon

Constructor Details

#initialize(obj, current_ability, show_text: true, view_context: nil) ⇒ CardNavBuilder

Returns a new instance of CardNavBuilder.



6
7
8
9
10
11
# File 'app/helpers/card_nav_builder.rb', line 6

def initialize(obj, current_ability, show_text: true, view_context: nil)
  @obj = obj
  @show_text = show_text
  @current_ability = current_ability
  @view_context = view_context
end

Instance Method Details



33
34
35
36
37
# File 'app/helpers/card_nav_builder.rb', line 33

def action_link(path, title: 'Action', icon_name: :play, method: :get, confirm: nil)
  return unless can?(:read, @obj)

  item_link(path, title, icon_name, confirm: confirm, method: method)
end


51
52
53
54
55
# File 'app/helpers/card_nav_builder.rb', line 51

def create_link(path, title: 'Add', icon_name: :add)
  return unless can?(:create, @obj)

  item_link(path, title, icon_name)
end


63
64
65
66
67
68
# File 'app/helpers/card_nav_builder.rb', line 63

def delete_link(path, confirm: nil, title: 'Delete')
  return unless can?(:manage, @obj)

  confirm ||= "Are you sure you want to delete this #{@obj.class_title}?"
  item_link(path, title, :delete, confirm: confirm, method: :delete, btn_class: 'text-danger')
end


57
58
59
60
61
# File 'app/helpers/card_nav_builder.rb', line 57

def duplicate_link(path, title: 'Duplicate', icon_name: :duplicate)
  return unless can?(:create, @obj)

  item_link(path, title, icon_name)
end


45
46
47
48
49
# File 'app/helpers/card_nav_builder.rb', line 45

def edit_link(path, title: 'Edit')
  return unless can?(:edit, @obj)

  item_link(path, title, :edit)
end


39
40
41
42
43
# File 'app/helpers/card_nav_builder.rb', line 39

def info_link( path, title: 'Info', icon_name: :info, method: :get)
  return unless can?(:read, @obj)

  item_link(path, title, icon_name, method: method)
end


20
21
22
23
24
25
# File 'app/helpers/card_nav_builder.rb', line 20

def reset_link(path, confirm: nil, title: 'Reset')
  return unless can?(:edit, @obj) && @obj.respond_to?(:overridden) && @obj.overridden?

  confirm ||= "Are you sure you want to #{title.downcase} this #{@obj.class_title}?"
  item_link(path, title, :replay, confirm: confirm)
end


13
14
15
16
17
18
# File 'app/helpers/card_nav_builder.rb', line 13

def restart_link(path, confirm: nil, title: 'Restart')
  return unless can?(:edit, @obj)

  confirm ||= "Are you sure you want to #{title.downcase} this #{@obj.class_title}?"
  item_link(path, title, :replay, confirm: confirm)
end


27
28
29
30
31
# File 'app/helpers/card_nav_builder.rb', line 27

def synchronize_link(path, title: 'Sync', icon_name: :sync)
  return unless can?(:edit, @obj)

  item_link(path, title, icon_name)
end