Class: HotFlash::Action
- Inherits:
-
Object
- Object
- HotFlash::Action
- Defined in:
- lib/hot_flash/action.rb
Instance Method Summary collapse
- #content ⇒ Object
- #disable! ⇒ Object
- #enable! ⇒ Object
- #enabled? ⇒ Boolean
-
#initialize(controller) ⇒ Action
constructor
A new instance of Action.
- #render ⇒ Object
- #render?(render_args) ⇒ Boolean
- #render_into(render_args) ⇒ Object
- #turbo_action ⇒ Object
- #turbo_target ⇒ Object
Constructor Details
#initialize(controller) ⇒ Action
Returns a new instance of Action.
3 4 5 6 7 8 9 |
# File 'lib/hot_flash/action.rb', line 3 def initialize(controller) @controller = controller @enabled = false @turbo_action = HotFlash.config.turbo_action @turbo_target = HotFlash.config.turbo_target @flash_method = HotFlash.config.flash_method end |
Instance Method Details
#content ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/hot_flash/action.rb', line 49 def content if @controller.respond_to?(@flash_method) return @controller.send(@flash_method) elsif @controller.helpers.respond_to?(@flash_method) return @controller.helpers.send(@flash_method) else raise NoMethodError, "#{@controller.class.name} doesn't respond to #{@flash_method}" end end |
#disable! ⇒ Object
15 16 17 |
# File 'lib/hot_flash/action.rb', line 15 def disable! @enabled = false end |
#enable! ⇒ Object
11 12 13 |
# File 'lib/hot_flash/action.rb', line 11 def enable! @enabled = true end |
#enabled? ⇒ Boolean
19 20 21 |
# File 'lib/hot_flash/action.rb', line 19 def enabled? @enabled end |
#render ⇒ Object
23 24 25 |
# File 'lib/hot_flash/action.rb', line 23 def render @controller.view_context.turbo_stream_action_tag(turbo_action, targets: turbo_target, template: content) end |
#render?(render_args) ⇒ Boolean
42 43 44 45 46 47 |
# File 'lib/hot_flash/action.rb', line 42 def render?(render_args) return false unless enabled? return false unless render_args[0] && render_args[0][:turbo_stream] true end |
#render_into(render_args) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/hot_flash/action.rb', line 35 def render_into(render_args) return render_args unless render?(render_args) render_args[0][:turbo_stream] << render render_args end |
#turbo_action ⇒ Object
27 28 29 |
# File 'lib/hot_flash/action.rb', line 27 def turbo_action @turbo_action end |
#turbo_target ⇒ Object
31 32 33 |
# File 'lib/hot_flash/action.rb', line 31 def turbo_target @turbo_target end |