Class: Plutonium::Action::Base

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

Overview

Base class for all actions in the Plutonium framework.

Direct Known Subclasses

Interactive, Simple

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, **options) ⇒ Base

Initialize a new action.

Parameters:

  • The name of the action.

  • The options for the action.

Options Hash (**options):

  • :label (String)

    The human-readable label for the action.

  • :description (String)

    The human-readable description for the action.

  • :icon (String)

    The icon associated with the action (e.g., ‘fa-edit’ for Font Awesome).

  • :color (Symbol)

    The color associated with the action (e.g., :primary, :secondary, :success, :warning, :danger).

  • :confirmation (String)

    The confirmation message to display before executing the action.

  • :route_options (RouteOptions, Hash)

    The routing options for the action.

  • :turbo_frame (String)

    The Turbo Frame ID for the action (used in Hotwire/Turbo Drive applications).

  • :return_to (String, Symbol)

    Override the return_to URL for this action. If not provided, defaults to current URL.

  • :bulk_action (Boolean) — default: false

    If true, applies to a bulk selection of records (e.g., “Mark Selected as Read”).

  • :collection_record_action (Boolean) — default: false

    If true, applies to records in a collection (e.g., “Edit Record” button in a table).

  • :record_action (Boolean) — default: false

    If true, applies to an individual record (e.g., “Delete” button on a Show page).

  • :resource_action (Boolean) — default: false

    If true, applies to the entire resource and can be used in any context (e.g., “Import from CSV”).

  • :category (Symbol)

    The category of the action. Determines visibility and grouping. Valid values include: @option options [Symbol] :primary Always shown and given prominence in the UI. @option options [Symbol] :secondary Shown in secondary menus or less prominent areas. @option options [Symbol] :danger Actions that require caution, often destructive operations.

  • :position (Integer) — default: 50

    The position of the action in its group. Lower numbers appear first.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/plutonium/action/base.rb', line 43

def initialize(name, **options)
  @name = name.to_sym
  @label = options[:label] || @name.to_s.titleize
  @description = options[:description]
  @icon = options[:icon] || Phlex::TablerIcons::ChevronRight
  @color = options[:color]
  @confirmation = options[:confirmation]
  @route_options = build_route_options(options[:route_options])
  @turbo = options[:turbo]
  @turbo_frame = options[:turbo_frame]
  @return_to = options[:return_to]
  @bulk_action = options[:bulk_action] || false
  @collection_record_action = options[:collection_record_action] || false
  @record_action = options[:record_action] || false
  @resource_action = options[:resource_action] || false
  @category = ActiveSupport::StringInquirer.new((options[:category] || :secondary).to_s)
  @position = options[:position] || 50

  freeze
end

Instance Attribute Details

#categorySymbol? (readonly)

The category of the action.

Returns:

  • the current value of category



18
19
20
# File 'lib/plutonium/action/base.rb', line 18

def category
  @category
end

#colorSymbol? (readonly)

The color associated with the action.

Returns:

  • the current value of color



18
19
20
# File 'lib/plutonium/action/base.rb', line 18

def color
  @color
end

#confirmationString? (readonly)

The confirmation message for the action.

Returns:

  • the current value of confirmation



18
19
20
# File 'lib/plutonium/action/base.rb', line 18

def confirmation
  @confirmation
end

#descriptionObject (readonly)

Returns the value of attribute description.



19
20
21
# File 'lib/plutonium/action/base.rb', line 19

def description
  @description
end

#iconString? (readonly)

The icon associated with the action.

Returns:

  • the current value of icon



18
19
20
# File 'lib/plutonium/action/base.rb', line 18

def icon
  @icon
end

#labelString (readonly)

The human-readable label for the action.

Returns:

  • the current value of label



18
19
20
# File 'lib/plutonium/action/base.rb', line 18

def label
  @label
end

#nameSymbol (readonly)

The name of the action.

Returns:

  • the current value of name



18
19
20
# File 'lib/plutonium/action/base.rb', line 18

def name
  @name
end

#positionInteger (readonly)

The position of the action within its category.

Returns:

  • the current value of position



18
19
20
# File 'lib/plutonium/action/base.rb', line 18

def position
  @position
end

#return_toObject (readonly)

Returns the value of attribute return_to.



19
20
21
# File 'lib/plutonium/action/base.rb', line 19

def return_to
  @return_to
end

#route_optionsRouteOptions (readonly)

The routing options for the action.

Returns:

  • the current value of route_options



18
19
20
# File 'lib/plutonium/action/base.rb', line 18

def route_options
  @route_options
end

#turboObject (readonly)

Returns the value of attribute turbo.



19
20
21
# File 'lib/plutonium/action/base.rb', line 19

def turbo
  @turbo
end

#turbo_frameString? (readonly)

The Turbo Frame ID for the action.

Returns:

  • the current value of turbo_frame



18
19
20
# File 'lib/plutonium/action/base.rb', line 18

def turbo_frame
  @turbo_frame
end

Instance Method Details

#bulk_action?Boolean

Returns Whether this is a bulk action.

Returns:

  • Whether this is a bulk action.



65
66
67
# File 'lib/plutonium/action/base.rb', line 65

def bulk_action?
  @bulk_action
end

#collection_record_action?Boolean

Returns Whether this is a collection record action.

Returns:

  • Whether this is a collection record action.



70
71
72
# File 'lib/plutonium/action/base.rb', line 70

def collection_record_action?
  @collection_record_action
end

#permitted_by?(policy) ⇒ Boolean

Returns:



84
85
86
# File 'lib/plutonium/action/base.rb', line 84

def permitted_by?(policy)
  policy.allowed_to?(:"#{name}?")
end

#record_action?Boolean

Returns Whether this is a record action.

Returns:

  • Whether this is a record action.



75
76
77
# File 'lib/plutonium/action/base.rb', line 75

def record_action?
  @record_action
end

#resource_action?Boolean

Returns Whether this is a resource action.

Returns:

  • Whether this is a resource action.



80
81
82
# File 'lib/plutonium/action/base.rb', line 80

def resource_action?
  @resource_action
end