Class: Decidim::DecidimAwesome::Admin::DestroyProposalCustomField
- Inherits:
-
Rectify::Command
- Object
- Rectify::Command
- Decidim::DecidimAwesome::Admin::DestroyProposalCustomField
- Defined in:
- app/commands/decidim/decidim_awesome/admin/destroy_proposal_custom_field.rb
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(key, organization) ⇒ DestroyProposalCustomField
constructor
Public: Initializes the command.
Constructor Details
#initialize(key, organization) ⇒ DestroyProposalCustomField
Public: Initializes the command.
key - the key to destroy inise proposal_custom_fields organization
11 12 13 14 |
# File 'app/commands/decidim/decidim_awesome/admin/destroy_proposal_custom_field.rb', line 11 def initialize(key, organization) @key = key @organization = organization 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 30 31 32 33 34 35 36 |
# File 'app/commands/decidim/decidim_awesome/admin/destroy_proposal_custom_field.rb', line 22 def call fields = AwesomeConfig.find_by(var: :proposal_custom_fields, organization: @organization) return broadcast(:invalid, "Not a hash") unless fields&.value.is_a? Hash return broadcast(:invalid, "#{key} key invalid") unless fields.value.has_key?(@key) fields.value.except!(@key) fields.save! # remove constrains associated (a new config var is generated automatically, by removing it, it will trigger destroy on dependents) constraint = AwesomeConfig.find_by(var: "proposal_custom_field_#{@key}", organization: @organization) constraint.destroy! if constraint.present? broadcast(:ok, @key) rescue StandardError => e broadcast(:invalid, e.) end |