Class: Plutonium::Action::Interactive

Inherits:
Base
  • Object
show all
Defined in:
lib/plutonium/action/interactive.rb

Overview

InteractiveAction class for handling interactive actions in the Plutonium framework

Defined Under Namespace

Classes: Factory

Instance Attribute Summary collapse

Attributes inherited from Base

#category, #color, #description, #icon, #label, #name, #position, #return_to, #route_options, #turbo, #turbo_frame

Instance Method Summary collapse

Methods inherited from Base

#bulk_action?, #collection_record_action?, #permitted_by?, #record_action?, #resource_action?

Constructor Details

#initialize(name, interaction:, immediate:, **options) ⇒ Interactive

Initialize a new InteractiveAction

Parameters:

  • name (Symbol)

    The name of the action

  • interaction (Class)

    The interaction class for this action

  • immediate (Boolean)

    Whether the action is executed immediately

  • options (Hash)

    Additional options for the action



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/plutonium/action/interactive.rb', line 18

def initialize(name, interaction:, immediate:, **options)
  @interaction = interaction
  @immediate = immediate

  options[:label] ||= interaction.label
  options[:description] ||= interaction.description
  options[:icon] ||= interaction.icon
  options[:turbo_frame] = "remote_modal" unless options.key?(:turbo_frame)

  super(name, **options)
end

Instance Attribute Details

#immediateBoolean (readonly)

Whether the action is executed immediately

Returns:

  • (Boolean)

    the current value of immediate



9
10
11
# File 'lib/plutonium/action/interactive.rb', line 9

def immediate
  @immediate
end

#interactionClass (readonly)

The interaction class associated with this action

Returns:

  • (Class)

    the current value of interaction



9
10
11
# File 'lib/plutonium/action/interactive.rb', line 9

def interaction
  @interaction
end

Instance Method Details

#confirmationString?

Get the confirmation message for the action

Returns:

  • (String, nil)

    The confirmation message or nil if not applicable



33
34
35
# File 'lib/plutonium/action/interactive.rb', line 33

def confirmation
  super || (@immediate ? "#{label}?" : nil)
end