Class: Decidim::Initiatives::Admin::CreateInitiativeTypeScope
- Inherits:
-
Rectify::Command
- Object
- Rectify::Command
- Decidim::Initiatives::Admin::CreateInitiativeTypeScope
- Defined in:
- app/commands/decidim/initiatives/admin/create_initiative_type_scope.rb
Overview
A command with all the business logic that creates a new initiative type scope
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form) ⇒ CreateInitiativeTypeScope
constructor
Public: Initializes the command.
Constructor Details
#initialize(form) ⇒ CreateInitiativeTypeScope
Public: Initializes the command.
form - A form object with the params.
11 12 13 |
# File 'app/commands/decidim/initiatives/admin/create_initiative_type_scope.rb', line 11 def initialize(form) @form = form 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.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/commands/decidim/initiatives/admin/create_initiative_type_scope.rb', line 21 def call return broadcast(:invalid) if form.invalid? initiative_type_scope = create_initiative_type_scope if initiative_type_scope.persisted? broadcast(:ok, initiative_type_scope) else initiative_type_scope.errors.each do |attribute, error| form.errors.add(attribute, error) end broadcast(:invalid) end end |