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



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

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


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

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

  item_link(path, title, icon_name)
end


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

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


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

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

  item_link(path, title, :edit)
end


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

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


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


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

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

  item_link(path, title, icon_name)
end