Class: Decidim::ActionDelegator::Admin::CreateDelegation
- Inherits:
-
Command
- Object
- Command
- Decidim::ActionDelegator::Admin::CreateDelegation
- Defined in:
- app/commands/decidim/action_delegator/admin/create_delegation.rb
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form, performed_by, current_setting) ⇒ CreateDelegation
constructor
Public: Initializes the command.
Constructor Details
#initialize(form, performed_by, current_setting) ⇒ CreateDelegation
Public: Initializes the command.
form - A form object with the params. delegated_by - The user performing the operation
11 12 13 14 15 |
# File 'app/commands/decidim/action_delegator/admin/create_delegation.rb', line 11 def initialize(form, performed_by, current_setting) @form = form @performed_by = performed_by @current_setting = current_setting end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid.
-
:invalid if the form wasn’t valid and we couldn’t proceed.
Returns nothing.
23 24 25 26 27 28 29 30 31 32 |
# File 'app/commands/decidim/action_delegator/admin/create_delegation.rb', line 23 def call return broadcast(:error, ) if form.invalid? || current_setting.nil? return broadcast(:error, ) if above_max_grants? create_delegation return broadcast(:ok) if delegation.persisted? broadcast(:error, delegation.errors..first) end |