Class: Decidim::DecidimAwesome::Admin::DestroyConstraint
- Includes:
- NeedsConstraintHelpers
- Defined in:
- app/commands/decidim/decidim_awesome/admin/destroy_constraint.rb
Instance Attribute Summary collapse
-
#constraint ⇒ Object
readonly
Returns the value of attribute constraint.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(constraint) ⇒ DestroyConstraint
constructor
Public: Initializes the command.
Constructor Details
#initialize(constraint) ⇒ DestroyConstraint
Public: Initializes the command.
constraint - A constraint constraint
12 13 14 |
# File 'app/commands/decidim/decidim_awesome/admin/destroy_constraint.rb', line 12 def initialize(constraint) @constraint = constraint end |
Instance Attribute Details
#constraint ⇒ Object (readonly)
Returns the value of attribute constraint.
31 32 33 |
# File 'app/commands/decidim/decidim_awesome/admin/destroy_constraint.rb', line 31 def constraint @constraint 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.
22 23 24 25 26 27 28 29 |
# File 'app/commands/decidim/decidim_awesome/admin/destroy_constraint.rb', line 22 def call return broadcast(:invalid, I18n.t("cannot_be_destroyed", scope: "decidim.decidim_awesome.admin.config.constraints")) unless constraint_can_be_destroyed?(constraint) constraint.destroy! broadcast(:ok) rescue StandardError => e broadcast(:invalid, e.) end |