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
-
#button ⇒ Object
readonly
Returns the value of attribute button.
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#confirmation ⇒ Object
readonly
Returns the value of attribute confirmation.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#link ⇒ Object
readonly
Returns the value of attribute link.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#return_to ⇒ Object
readonly
Returns the value of attribute return_to.
-
#route_options ⇒ Object
readonly
Returns the value of attribute route_options.
-
#turbo ⇒ Object
readonly
Returns the value of attribute turbo.
Instance Method Summary collapse
- #bulk_action? ⇒ Boolean
- #button_attributes(attributes) ⇒ Object
- #collection_record_action? ⇒ Boolean
-
#condition_met?(view_context, record: nil) ⇒ Boolean
Display-only visibility gate, mirroring the
condition:proc on inputs/displays/columns. -
#hidden? ⇒ Boolean
True when this action must never render.
-
#initialize(name, **options) ⇒ Base
constructor
A new instance of Base.
-
#link_attributes(attributes) ⇒ Object
Merge points for rendering surfaces: deep-merge the author's bag over the framework-built attributes for the element being rendered, with the author winning on every key.
-
#modal_mode(definition = nil) ⇒ Object
Resolves to the definition's
modal_modewhen unset on the action. -
#modal_size(definition = nil) ⇒ Object
Resolves to the definition's
modal_sizewhen unset on the action. - #permitted_by?(policy) ⇒ Boolean
- #record_action? ⇒ Boolean
- #resource_action? ⇒ Boolean
-
#turbo_frame(definition = nil) ⇒ Object
Downgrades the remote-modal frame to nil when the definition has
modal false, so the link navigates as a full page instead of targeting a frame that won't exist. -
#with(**overrides) ⇒ Object
Returns a new Action with the given options merged over this one.
Constructor Details
#initialize(name, **options) ⇒ Base
Returns a new instance of Base.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/plutonium/action/base.rb', line 11 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 @hidden = [:hidden] || false @category = ActiveSupport::StringInquirer.new(([:category] || :secondary).to_s) @position = [:position] || 50 @modal_mode = [:modal] @modal_size = [:size] @condition = [:condition] # Author-supplied HTML attributes, keyed by the element they target: # `link:` merges onto every anchor rendering (the GET link and dropdown # items — which are anchors even for non-GET actions), `button:` onto # the button_to <form> (the non-GET toolbar rendering). Both deep-merge # over the framework's attributes at render time, with the author # winning. @link = normalize_html_attribute_bag([:link], :link) @button = normalize_html_attribute_bag([:button], :button) validate_modal_mode! validate_modal_size! freeze end |
Instance Attribute Details
#button ⇒ Object (readonly)
Returns the value of attribute button.
9 10 11 |
# File 'lib/plutonium/action/base.rb', line 9 def @button end |
#category ⇒ Object (readonly)
Returns the value of attribute category.
9 10 11 |
# File 'lib/plutonium/action/base.rb', line 9 def category @category end |
#color ⇒ Object (readonly)
Returns the value of attribute color.
9 10 11 |
# File 'lib/plutonium/action/base.rb', line 9 def color @color end |
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
9 10 11 |
# File 'lib/plutonium/action/base.rb', line 9 def condition @condition end |
#confirmation ⇒ Object (readonly)
Returns the value of attribute confirmation.
9 10 11 |
# File 'lib/plutonium/action/base.rb', line 9 def confirmation @confirmation end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
9 10 11 |
# File 'lib/plutonium/action/base.rb', line 9 def description @description end |
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
9 10 11 |
# File 'lib/plutonium/action/base.rb', line 9 def icon @icon end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
9 10 11 |
# File 'lib/plutonium/action/base.rb', line 9 def label @label end |
#link ⇒ Object (readonly)
Returns the value of attribute link.
9 10 11 |
# File 'lib/plutonium/action/base.rb', line 9 def link @link end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/plutonium/action/base.rb', line 9 def name @name end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
9 10 11 |
# File 'lib/plutonium/action/base.rb', line 9 def position @position end |
#return_to ⇒ Object (readonly)
Returns the value of attribute return_to.
9 10 11 |
# File 'lib/plutonium/action/base.rb', line 9 def return_to @return_to end |
#route_options ⇒ Object (readonly)
Returns the value of attribute route_options.
9 10 11 |
# File 'lib/plutonium/action/base.rb', line 9 def @route_options end |
#turbo ⇒ Object (readonly)
Returns the value of attribute turbo.
9 10 11 |
# File 'lib/plutonium/action/base.rb', line 9 def turbo @turbo end |
Instance Method Details
#bulk_action? ⇒ Boolean
75 |
# File 'lib/plutonium/action/base.rb', line 75 def bulk_action? = @bulk_action |
#button_attributes(attributes) ⇒ Object
119 120 121 |
# File 'lib/plutonium/action/base.rb', line 119 def (attributes) (@button, attributes) end |
#collection_record_action? ⇒ Boolean
76 |
# File 'lib/plutonium/action/base.rb', line 76 def collection_record_action? = @collection_record_action |
#condition_met?(view_context, record: nil) ⇒ Boolean
Display-only visibility gate, mirroring the condition: proc on
inputs/displays/columns. Returns true when no condition is set.
The proc is evaluated against a ConditionContext: object/record is
the contextual record (nil for resource/bulk actions), and every other
call delegates to the view context (current_user, params, request,
allowed_to?, resource_record!, …).
NOT an authorization boundary — a hidden action still has a live route; keep authorization in the policy.
103 104 105 106 |
# File 'lib/plutonium/action/base.rb', line 103 def condition_met?(view_context, record: nil) return true if @condition.nil? ConditionContext.new(view_context, record).instance_exec(&@condition) end |
#hidden? ⇒ Boolean
True when this action must never render. It still has a live route, policy predicate, and (if interactive) form + params machinery — it is simply reachable only by something other than a button: a kanban drop, a drag-reorder, a custom Stimulus controller.
Display-only, like #condition_met? — NOT an authorization boundary. Keep authorization in the policy.
87 |
# File 'lib/plutonium/action/base.rb', line 87 def hidden? = @hidden |
#link_attributes(attributes) ⇒ Object
Merge points for rendering surfaces: deep-merge the author's bag over
the framework-built attributes for the element being rendered, with
the author winning on every key. link_attributes is for anchors
(the GET toolbar link, dropdown items — anchors even for non-GET
actions — bulk-action links, kanban column actions, card show links);
button_attributes is for the button_to
115 116 117 |
# File 'lib/plutonium/action/base.rb', line 115 def link_attributes(attributes) (@link, attributes) end |
#modal_mode(definition = nil) ⇒ Object
Resolves to the definition's modal_mode when unset on the action.
47 48 49 50 |
# File 'lib/plutonium/action/base.rb', line 47 def modal_mode(definition = nil) return @modal_mode if @modal_mode || definition.nil? definition.modal_mode end |
#modal_size(definition = nil) ⇒ Object
Resolves to the definition's modal_size when unset on the action.
53 54 55 56 |
# File 'lib/plutonium/action/base.rb', line 53 def modal_size(definition = nil) return @modal_size if @modal_size || definition.nil? definition.modal_size end |
#permitted_by?(policy) ⇒ Boolean
89 90 91 |
# File 'lib/plutonium/action/base.rb', line 89 def permitted_by?(policy) policy.allowed_to?(:"#{name}?") end |
#record_action? ⇒ Boolean
77 |
# File 'lib/plutonium/action/base.rb', line 77 def record_action? = @record_action |
#resource_action? ⇒ Boolean
78 |
# File 'lib/plutonium/action/base.rb', line 78 def resource_action? = @resource_action |
#turbo_frame(definition = nil) ⇒ Object
Downgrades the remote-modal frame to nil when the definition has
modal false, so the link navigates as a full page instead of
targeting a frame that won't exist. Other frames pass through.
The canonical :show action carries no explicit frame; instead it reads
the definition's show_in so a resource can open its show page in a
modal (show_in :modal) or full-page (:page, default) without the
caller threading a frame. This is deliberately independent of
modal_mode (which styles :new/:edit) — show is always centered.
67 68 69 70 71 72 73 |
# File 'lib/plutonium/action/base.rb', line 67 def turbo_frame(definition = nil) return nil if definition && targets_remote_modal? && definition.modal_mode == false if definition && name == :show && @turbo_frame.nil? return (definition.show_in == :modal) ? Plutonium::REMOTE_MODAL_FRAME : nil end @turbo_frame end |
#with(**overrides) ⇒ Object
Returns a new Action with the given options merged over this one.
124 125 126 |
# File 'lib/plutonium/action/base.rb', line 124 def with(**overrides) self.class.new(name, **.merge(overrides)) end |