Class: Decidim::Demographics::Admin::UpdateDemographicsSettings

Inherits:
Command
  • Object
show all
Defined in:
decidim-demographics/app/commands/decidim/demographics/admin/update_demographics_settings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Command

call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events

Constructor Details

#initialize(form) ⇒ UpdateDemographicsSettings

Initializes an UpdateDemographicsSettings Command.

Parameters:

  • form
    • The form from which to get the data.



10
11
12
# File 'decidim-demographics/app/commands/decidim/demographics/admin/update_demographics_settings.rb', line 10

def initialize(form)
  @form = form
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Attribute Details

#formObject (readonly)

Returns the value of attribute form.



14
15
16
# File 'decidim-demographics/app/commands/decidim/demographics/admin/update_demographics_settings.rb', line 14

def form
  @form
end

Instance Method Details

#callObject

Updates the demographic data if valid.

Broadcasts :ok if successful, :invalid otherwise.



22
23
24
25
26
27
28
29
30
# File 'decidim-demographics/app/commands/decidim/demographics/admin/update_demographics_settings.rb', line 22

def call
  Decidim.traceability.perform_action!("update", demographic, current_user) do
    update_demographic_settings
  end

  broadcast(:ok)
rescue ActiveRecord::RecordInvalid
  broadcast(:invalid)
end