Class: Plutonium::Action::Base
- Inherits:
-
Object
- Object
- Plutonium::Action::Base
- Defined in:
- lib/plutonium/action/base.rb
Overview
Base class for all actions in the Plutonium framework.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#category ⇒ Symbol?
readonly
The category of the action.
-
#color ⇒ Symbol?
readonly
The color associated with the action.
-
#confirmation ⇒ String?
readonly
The confirmation message for the action.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#icon ⇒ String?
readonly
The icon associated with the action.
-
#label ⇒ String
readonly
The human-readable label for the action.
-
#modal ⇒ Object
readonly
Returns the value of attribute modal.
-
#name ⇒ Symbol
readonly
The name of the action.
-
#position ⇒ Integer
readonly
The position of the action within its category.
-
#return_to ⇒ Object
readonly
Returns the value of attribute return_to.
-
#route_options ⇒ RouteOptions
readonly
The routing options for the action.
-
#turbo ⇒ Object
readonly
Returns the value of attribute turbo.
-
#turbo_frame ⇒ String?
readonly
The Turbo Frame ID for the action.
Instance Method Summary collapse
-
#bulk_action? ⇒ Boolean
Whether this is a bulk action.
-
#collection_record_action? ⇒ Boolean
Whether this is a collection record action.
-
#initialize(name, **options) ⇒ Base
constructor
Initialize a new action.
- #permitted_by?(policy) ⇒ Boolean
-
#record_action? ⇒ Boolean
Whether this is a record action.
-
#resource_action? ⇒ Boolean
Whether this is a resource action.
-
#with(**overrides) ⇒ Object
Returns a new Action with the given options merged over this one.
Constructor Details
#initialize(name, **options) ⇒ Base
Initialize a new action.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/plutonium/action/base.rb', line 43 def initialize(name, **) @name = name.to_sym @label = [:label] || @name.to_s.titleize @description = [:description] @icon = [:icon] || Phlex::TablerIcons::ChevronRight @color = [:color] @confirmation = [:confirmation] @route_options = ([:route_options]) @turbo = [:turbo] @turbo_frame = [:turbo_frame] @return_to = [:return_to] @bulk_action = [:bulk_action] || false @collection_record_action = [:collection_record_action] || false @record_action = [:record_action] || false @resource_action = [:resource_action] || false @category = ActiveSupport::StringInquirer.new(([:category] || :secondary).to_s) @position = [:position] || 50 @modal = [:modal] || :centered validate_modal! freeze end |
Instance Attribute Details
#category ⇒ Symbol? (readonly)
The category of the action.
18 19 20 |
# File 'lib/plutonium/action/base.rb', line 18 def category @category end |
#color ⇒ Symbol? (readonly)
The color associated with the action.
18 19 20 |
# File 'lib/plutonium/action/base.rb', line 18 def color @color end |
#confirmation ⇒ String? (readonly)
The confirmation message for the action.
18 19 20 |
# File 'lib/plutonium/action/base.rb', line 18 def confirmation @confirmation end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
19 20 21 |
# File 'lib/plutonium/action/base.rb', line 19 def description @description end |
#icon ⇒ String? (readonly)
The icon associated with the action.
18 19 20 |
# File 'lib/plutonium/action/base.rb', line 18 def icon @icon end |
#label ⇒ String (readonly)
The human-readable label for the action.
18 19 20 |
# File 'lib/plutonium/action/base.rb', line 18 def label @label end |
#modal ⇒ Object (readonly)
Returns the value of attribute modal.
19 20 21 |
# File 'lib/plutonium/action/base.rb', line 19 def modal @modal end |
#name ⇒ Symbol (readonly)
The name of the action.
18 19 20 |
# File 'lib/plutonium/action/base.rb', line 18 def name @name end |
#position ⇒ Integer (readonly)
The position of the action within its category.
18 19 20 |
# File 'lib/plutonium/action/base.rb', line 18 def position @position end |
#return_to ⇒ Object (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_options ⇒ RouteOptions (readonly)
The routing options for the action.
18 19 20 |
# File 'lib/plutonium/action/base.rb', line 18 def @route_options end |
#turbo ⇒ Object (readonly)
Returns the value of attribute turbo.
19 20 21 |
# File 'lib/plutonium/action/base.rb', line 19 def turbo @turbo end |
#turbo_frame ⇒ String? (readonly)
The Turbo Frame ID for the action.
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.
67 68 69 |
# File 'lib/plutonium/action/base.rb', line 67 def bulk_action? @bulk_action end |
#collection_record_action? ⇒ Boolean
Returns Whether this is a collection record action.
72 73 74 |
# File 'lib/plutonium/action/base.rb', line 72 def collection_record_action? @collection_record_action end |
#permitted_by?(policy) ⇒ Boolean
86 87 88 |
# File 'lib/plutonium/action/base.rb', line 86 def permitted_by?(policy) policy.allowed_to?(:"#{name}?") end |
#record_action? ⇒ Boolean
Returns Whether this is a record action.
77 78 79 |
# File 'lib/plutonium/action/base.rb', line 77 def record_action? @record_action end |
#resource_action? ⇒ Boolean
Returns Whether this is a resource action.
82 83 84 |
# File 'lib/plutonium/action/base.rb', line 82 def resource_action? @resource_action end |
#with(**overrides) ⇒ Object
Returns a new Action with the given options merged over this one. Used by the resource definition to derive variants (e.g. dropping ‘turbo_frame` when `modal false` is configured) without mutating the frozen original.
94 95 96 |
# File 'lib/plutonium/action/base.rb', line 94 def with(**overrides) self.class.new(name, **.merge(overrides)) end |