Class: Decidim::Admin::CreateComponent

Inherits:
Command
  • Object
show all
Defined in:
decidim-admin/app/commands/decidim/admin/create_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) ⇒ CreateComponent

Public: Initializes the command.

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



12
13
14
15
# File 'decidim-admin/app/commands/decidim/admin/create_component.rb', line 12

def initialize(form)
  @form = form
  @manifest = form.manifest
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.



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

def form
  @form
end

#manifestObject (readonly)

Returns the value of attribute manifest.



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

def manifest
  @manifest
end

#participatory_spaceObject (readonly)

Returns the value of attribute participatory_space.



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

def participatory_space
  @participatory_space
end

Instance Method Details

#callObject

Public: Creates the Component.

Broadcasts :ok if created, :invalid otherwise.



20
21
22
23
24
25
26
27
28
29
# File 'decidim-admin/app/commands/decidim/admin/create_component.rb', line 20

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

  transaction do
    create_component
    run_hooks
  end

  broadcast(:ok)
end