Class: Decidim::Admin::UpdateComponent

Inherits:
Rectify::Command
  • Object
show all
Defined in:
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

Constructor Details

#initialize(form, component) ⇒ 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
# File 'app/commands/decidim/admin/update_component.rb', line 13

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

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



7
8
9
# File '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 '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 '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.



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

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

  transaction do
    update_component
    run_hooks
  end

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