Class: IronAdmin::ToolAction
- Inherits:
-
Object
- Object
- IronAdmin::ToolAction
- Defined in:
- lib/iron_admin/tool_action.rb
Overview
Value object representing a declared action on a Tool.
Stores action metadata: display label, icon, confirmation settings, form fields to collect before execution, and authorization condition.
Instance Attribute Summary collapse
-
#condition ⇒ Proc?
readonly
Condition proc that receives current_user, returns boolean.
-
#confirm ⇒ Boolean
readonly
Whether to show confirmation dialog.
-
#confirm_message ⇒ String?
readonly
Custom confirmation message.
-
#form_fields ⇒ Array<ActionField>
readonly
Form fields to collect before execution.
-
#icon ⇒ String?
readonly
Heroicon name.
-
#label ⇒ String
readonly
Display label.
-
#name ⇒ Symbol
readonly
Action method name.
Instance Method Summary collapse
-
#allowed?(user) ⇒ Boolean
Checks if the action is allowed for the given user.
-
#has_form? ⇒ Boolean
Whether this action has form fields to collect.
-
#initialize(name:, label: nil, icon: nil, confirm: false, confirm_message: nil, form_fields: [], condition: nil) ⇒ ToolAction
constructor
A new instance of ToolAction.
Constructor Details
#initialize(name:, label: nil, icon: nil, confirm: false, confirm_message: nil, form_fields: [], condition: nil) ⇒ ToolAction
Returns a new instance of ToolAction.
40 41 42 43 44 45 46 47 48 |
# File 'lib/iron_admin/tool_action.rb', line 40 def initialize(name:, label: nil, icon: nil, confirm: false, confirm_message: nil, form_fields: [], condition: nil) @name = name.to_sym @label = label || name.to_s.humanize @icon = icon @confirm = confirm @confirm_message = @form_fields = coerce_form_fields(form_fields) @condition = condition end |
Instance Attribute Details
#condition ⇒ Proc? (readonly)
Returns Condition proc that receives current_user, returns boolean.
38 39 40 |
# File 'lib/iron_admin/tool_action.rb', line 38 def condition @condition end |
#confirm ⇒ Boolean (readonly)
Returns Whether to show confirmation dialog.
29 30 31 |
# File 'lib/iron_admin/tool_action.rb', line 29 def confirm @confirm end |
#confirm_message ⇒ String? (readonly)
Returns Custom confirmation message.
32 33 34 |
# File 'lib/iron_admin/tool_action.rb', line 32 def @confirm_message end |
#form_fields ⇒ Array<ActionField> (readonly)
Returns Form fields to collect before execution.
35 36 37 |
# File 'lib/iron_admin/tool_action.rb', line 35 def form_fields @form_fields end |
#icon ⇒ String? (readonly)
Returns Heroicon name.
26 27 28 |
# File 'lib/iron_admin/tool_action.rb', line 26 def icon @icon end |
#label ⇒ String (readonly)
Returns Display label.
23 24 25 |
# File 'lib/iron_admin/tool_action.rb', line 23 def label @label end |
#name ⇒ Symbol (readonly)
Returns Action method name.
20 21 22 |
# File 'lib/iron_admin/tool_action.rb', line 20 def name @name end |
Instance Method Details
#allowed?(user) ⇒ Boolean
Checks if the action is allowed for the given user.
59 60 61 62 63 |
# File 'lib/iron_admin/tool_action.rb', line 59 def allowed?(user) return true if condition.nil? condition.call(user) end |
#has_form? ⇒ Boolean
Returns Whether this action has form fields to collect.
51 52 53 |
# File 'lib/iron_admin/tool_action.rb', line 51 def has_form? # rubocop:disable Naming/PredicatePrefix form_fields.any? end |