Class: Decidim::Admin::UpdateComponent

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

Overview

This command gets called when a component is created from the admin panel.

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, component, user) ⇒ UpdateComponent

Public: Initializes the command.

form - The form from which the data in this component comes from. component - The component to update.



13
14
15
16
17
18
# File 'decidim-admin/app/commands/decidim/admin/update_component.rb', line 13

def initialize(form, component, user)
  @manifest = component.manifest
  @form = form
  @component = component
  @user = user
end

Dynamic Method Handling

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

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



7
8
9
# File 'decidim-admin/app/commands/decidim/admin/update_component.rb', line 7

def component
  @component
end

#formObject (readonly)

Returns the value of attribute form.



7
8
9
# File 'decidim-admin/app/commands/decidim/admin/update_component.rb', line 7

def form
  @form
end

#previous_settingsObject (readonly)

Returns the value of attribute previous_settings.



7
8
9
# File 'decidim-admin/app/commands/decidim/admin/update_component.rb', line 7

def previous_settings
  @previous_settings
end

Instance Method Details

#callObject

Public: Creates the Component.

Broadcasts :ok if created, :invalid otherwise.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'decidim-admin/app/commands/decidim/admin/update_component.rb', line 23

def call
  return broadcast(:invalid) if form.invalid?

  Decidim.traceability.perform_action!("update", @component, @user) do
    transaction do
      update_component
      run_hooks
    end
  end

  broadcast(:ok, settings_changed?, previous_settings, current_settings)
end