Class: Decidim::DecidimAwesome::Admin::DestroyScopedStyle
- Inherits:
-
Command
- Object
- Command
- Command
- Decidim::DecidimAwesome::Admin::DestroyScopedStyle
- Defined in:
- app/commands/decidim/decidim_awesome/admin/destroy_scoped_style.rb
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(key, organization) ⇒ DestroyScopedStyle
constructor
Public: Initializes the command.
Constructor Details
#initialize(key, organization) ⇒ DestroyScopedStyle
Public: Initializes the command.
key - the key to destroy inside scoped_styles organization
11 12 13 14 |
# File 'app/commands/decidim/decidim_awesome/admin/destroy_scoped_style.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_scoped_style.rb', line 22 def call styles = AwesomeConfig.find_by(var: :scoped_styles, organization: @organization) return broadcast(:invalid, "Not a hash") unless styles&.value.is_a? Hash return broadcast(:invalid, "#{key} key invalid") unless styles.value.has_key?(@key) styles.value.except!(@key) styles.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: "scoped_style_#{@key}", organization: @organization) constraint.destroy! if constraint.present? broadcast(:ok, @key) rescue StandardError => e broadcast(:invalid, e.) end |