Class: LcpRuby::Presenter::ActionSet
- Inherits:
-
Object
- Object
- LcpRuby::Presenter::ActionSet
- Defined in:
- lib/lcp_ruby/presenter/action_set.rb
Constant Summary collapse
- CRUD_ACTION_NAMES =
Standard CRUD action names (including aliases) checked via can?() against the CRUD list. Non-CRUD built-in actions (e.g., export) are checked via can_execute_action?() instead.
%w[index show create update destroy edit new].freeze
- RECORD_RULE_ACTION_NAMES =
Action names (including aliases) whose record rules should hide the button. “edit” maps to “update” via alias; “show” is intentionally excluded.
%w[edit update destroy restore permanently_destroy].freeze
Instance Attribute Summary collapse
-
#permission_evaluator ⇒ Object
readonly
Returns the value of attribute permission_evaluator.
-
#presenter_definition ⇒ Object
readonly
Returns the value of attribute presenter_definition.
Instance Method Summary collapse
- #batch_actions ⇒ Object
- #collection_actions ⇒ Object
- #form_actions(record) ⇒ Object
-
#initialize(presenter_definition, permission_evaluator, context: {}) ⇒ ActionSet
constructor
A new instance of ActionSet.
- #single_actions(record = nil) ⇒ Object
Constructor Details
#initialize(presenter_definition, permission_evaluator, context: {}) ⇒ ActionSet
Returns a new instance of ActionSet.
14 15 16 17 18 |
# File 'lib/lcp_ruby/presenter/action_set.rb', line 14 def initialize(presenter_definition, , context: {}) @presenter_definition = presenter_definition @permission_evaluator = @context = context end |
Instance Attribute Details
#permission_evaluator ⇒ Object (readonly)
Returns the value of attribute permission_evaluator.
12 13 14 |
# File 'lib/lcp_ruby/presenter/action_set.rb', line 12 def @permission_evaluator end |
#presenter_definition ⇒ Object (readonly)
Returns the value of attribute presenter_definition.
12 13 14 |
# File 'lib/lcp_ruby/presenter/action_set.rb', line 12 def presenter_definition @presenter_definition end |
Instance Method Details
#batch_actions ⇒ Object
54 55 56 57 58 |
# File 'lib/lcp_ruby/presenter/action_set.rb', line 54 def batch_actions return [] if presenter_definition.grouped_query? filter_actions(presenter_definition.batch_actions) end |
#collection_actions ⇒ Object
20 21 22 |
# File 'lib/lcp_ruby/presenter/action_set.rb', line 20 def collection_actions filter_actions(presenter_definition.collection_actions) end |
#form_actions(record) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/lcp_ruby/presenter/action_set.rb', line 60 def form_actions(record) actions = presenter_definition.form_actions actions = filter_form_actions(actions, record) actions = actions.map { |a| resolve_confirm(a) } actions .select { |a| action_visible_for_record?(a, record) } .map { |a| a.merge("_disabled" => action_disabled_for_record?(a, record)) } end |
#single_actions(record = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/lcp_ruby/presenter/action_set.rb', line 24 def single_actions(record = nil) return [] if presenter_definition.grouped_query? base_actions = presenter_definition.single_actions actions = filter_actions(base_actions) actions = actions.map { |a| resolve_confirm(a) } return actions unless record actions = actions .select { |a| action_permitted_for_record?(a, record) } .select { |a| action_visible_for_record?(a, record) } .map { |a| a.merge("_disabled" => action_disabled_for_record?(a, record)) } # Append workflow transition actions wf = workflow_for_model if wf transition_actions = Workflow::TransitionActionBuilder.build_actions( record, workflow_definition: wf, user: .user, evaluator: , presenter_overrides: workflow_presenter_overrides(base_actions), state_machine: workflow_state_machine ) actions.concat(transition_actions) end actions end |