Class: Decidim::DecidimAwesome::Admin::UpdateCookieCategory
- Inherits:
-
Command
- Object
- Command
- Decidim::DecidimAwesome::Admin::UpdateCookieCategory
- Defined in:
- app/commands/decidim/decidim_awesome/admin/update_cookie_category.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#form ⇒ Object
readonly
Returns the value of attribute form.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form) ⇒ UpdateCookieCategory
constructor
Public: Initializes the command.
Constructor Details
#initialize(form) ⇒ UpdateCookieCategory
Public: Initializes the command.
form - A form object with the params. config - The AwesomeConfig instance for cookie management.
11 12 13 14 |
# File 'app/commands/decidim/decidim_awesome/admin/update_cookie_category.rb', line 11 def initialize(form) @form = form @config = AwesomeConfig.find_or_initialize_by(organization: form.current_organization, var: :cookie_management) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
16 17 18 |
# File 'app/commands/decidim/decidim_awesome/admin/update_cookie_category.rb', line 16 def config @config end |
#form ⇒ Object (readonly)
Returns the value of attribute form.
16 17 18 |
# File 'app/commands/decidim/decidim_awesome/admin/update_cookie_category.rb', line 16 def form @form end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid.
-
:invalid if the form is invalid, category not found, or slug already exists.
Returns nothing.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/commands/decidim/decidim_awesome/admin/update_cookie_category.rb', line 24 def call return broadcast(:invalid) if form.invalid? config.value ||= {} # Handle slug change by deleting old key config.value[form.slug] = config.value.delete(form.id) if form.id && form.slug != form.id config.value[form.slug] = form.to_params.merge("items" => items) config.save! broadcast(:ok) rescue StandardError => e broadcast(:invalid, e.) end |