Class: Decidim::DecidimAwesome::Admin::UpdateConfig
- Defined in:
- app/commands/decidim/decidim_awesome/admin/update_config.rb
Instance Attribute Summary collapse
-
#form ⇒ Object
readonly
Returns the value of attribute form.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form) ⇒ UpdateConfig
constructor
Public: Initializes the command.
Constructor Details
#initialize(form) ⇒ UpdateConfig
Public: Initializes the command.
form - A config form
10 11 12 |
# File 'app/commands/decidim/decidim_awesome/admin/update_config.rb', line 10 def initialize(form) @form = form end |
Instance Attribute Details
#form ⇒ Object (readonly)
Returns the value of attribute form.
43 44 45 |
# File 'app/commands/decidim/decidim_awesome/admin/update_config.rb', line 43 def form @form 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.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/commands/decidim/decidim_awesome/admin/update_config.rb', line 20 def call if form.invalid? = form.errors[:scoped_styles].join("; ") if @form.errors[:scoped_styles].any? = form.errors[:scoped_admins].join("; ") if @form.errors[:scoped_admins].any? return broadcast(:invalid, , form.errors) end begin form.attributes.each do |key, val| # ignore nil attributes (must specifically be set to false if necessary) next unless form.valid_keys.include?(key.to_sym) setting = AwesomeConfig.find_or_initialize_by(var: key, organization: form.current_organization) setting.value = val.respond_to?(:attributes) ? val.attributes : val setting.save! end broadcast(:ok) rescue ActiveRecord::RecordInvalid => e broadcast(:invalid, e.) end end |