Class: Decidim::Templates::Admin::CreateTemplate

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

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(form) ⇒ CreateTemplate

Initializes the command.

form - The source for this generic Template.



10
11
12
# File 'decidim-templates/app/commands/decidim/templates/admin/create_template.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 Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if the form was not valid and we could not proceed.

Returns nothing.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'decidim-templates/app/commands/decidim/templates/admin/create_template.rb', line 20

def call
  return broadcast(:invalid) unless @form.valid?

  @template = Decidim.traceability.create!(
    Template,
    @form.current_user,
    name: @form.name,
    description: @form.description,
    organization: @form.current_organization,
    field_values:,
    target:
  )

  assign_template!

  broadcast(:ok, @template)
end