Class: Decidim::DecidimAwesome::Admin::UpdateConstraint
- Defined in:
- app/commands/decidim/decidim_awesome/admin/update_constraint.rb
Instance Attribute Summary collapse
-
#form ⇒ Object
readonly
Returns the value of attribute form.
Instance Method Summary collapse
- #attributes ⇒ Object
-
#call ⇒ Object
Executes the command.
-
#initialize(form) ⇒ UpdateConstraint
constructor
Public: Initializes the command.
Constructor Details
#initialize(form) ⇒ UpdateConstraint
Public: Initializes the command.
form - A constraint form
10 11 12 |
# File 'app/commands/decidim/decidim_awesome/admin/update_constraint.rb', line 10 def initialize(form) @form = form end |
Instance Attribute Details
#form ⇒ Object (readonly)
Returns the value of attribute form.
36 37 38 |
# File 'app/commands/decidim/decidim_awesome/admin/update_constraint.rb', line 36 def form @form end |
Instance Method Details
#attributes ⇒ Object
38 39 40 |
# File 'app/commands/decidim/decidim_awesome/admin/update_constraint.rb', line 38 def attributes form.attributes.filter { |key, val| key != "id" && val.present? } end |
#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 |
# File 'app/commands/decidim/decidim_awesome/admin/update_constraint.rb', line 20 def call return broadcast(:invalid, form.errors..join(". ")) if form.invalid? return broadcast(:invalid) if attributes.blank? begin constraint = ConfigConstraint.find(form.id) constraint.settings = attributes constraint.save! broadcast(:ok) rescue ActiveRecord::RecordNotUnique broadcast(:invalid, I18n.t("decidim.decidim_awesome.admin.constraints.errors.not_unique")) rescue StandardError => e broadcast(:invalid, e.) end end |