Class: CardNavBuilder
Instance Method Summary
collapse
-
#action_link(path, title: 'Action', icon_name: :play, method: :get, confirm: nil) ⇒ Object
-
#create_link(path, title: 'Add', icon_name: :add) ⇒ Object
-
#delete_link(path, confirm: nil, title: 'Delete') ⇒ Object
-
#duplicate_link(path, title: 'Duplicate', icon_name: :duplicate) ⇒ Object
-
#edit_link(path, title: 'Edit') ⇒ Object
-
#info_link(path, title: 'Info', icon_name: :info, method: :get) ⇒ Object
-
#initialize(obj, current_ability, show_text: true, view_context: nil) ⇒ CardNavBuilder
constructor
A new instance of CardNavBuilder.
-
#reset_link(path, confirm: nil, title: 'Reset') ⇒ Object
-
#restart_link(path, confirm: nil, title: 'Restart') ⇒ Object
-
#synchronize_link(path, title: 'Sync', icon_name: :sync) ⇒ Object
#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
#action_link(path, title: 'Action', icon_name: :play, method: :get, confirm: nil) ⇒ Object
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
|
#create_link(path, title: 'Add', icon_name: :add) ⇒ Object
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
|
#delete_link(path, confirm: nil, title: 'Delete') ⇒ Object
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
|
#duplicate_link(path, title: 'Duplicate', icon_name: :duplicate) ⇒ Object
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
|
#edit_link(path, title: 'Edit') ⇒ Object
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
|
#info_link(path, title: 'Info', icon_name: :info, method: :get) ⇒ Object
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
|
#reset_link(path, confirm: nil, title: 'Reset') ⇒ Object
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
|
#restart_link(path, confirm: nil, title: 'Restart') ⇒ Object
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
|
#synchronize_link(path, title: 'Sync', icon_name: :sync) ⇒ Object
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
|