Class: Decidim::DecidimAwesome::Admin::CreateConstraint
- Defined in:
- app/commands/decidim/decidim_awesome/admin/create_constraint.rb
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form) ⇒ CreateConstraint
constructor
Public: Initializes the command.
Constructor Details
#initialize(form) ⇒ CreateConstraint
Public: Initializes the command.
form - A constraint form
10 11 12 |
# File 'app/commands/decidim/decidim_awesome/admin/create_constraint.rb', line 10 def initialize(form) @form = form end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid.
-
:invalid if we couldn’t proceed.
Returns nothing.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/commands/decidim/decidim_awesome/admin/create_constraint.rb', line 20 def call return broadcast(:invalid, form.errors..join(". ")) if form.invalid? return broadcast(:invalid) if attributes.blank? begin @constraint = ConfigConstraint.create!( awesome_config: form.context.setting, settings: attributes ) broadcast(:ok, @constraint) rescue ActiveRecord::RecordNotUnique broadcast(:invalid, I18n.t("decidim.decidim_awesome.admin.constraints.errors.not_unique")) rescue StandardError => e broadcast(:invalid, e.) end end |