Class: Decidim::Commands::CreateResource

Inherits:
Decidim::Command show all
Includes:
ResourceHandler
Defined in:
decidim-core/lib/decidim/commands/create_resource.rb

Instance Method Summary collapse

Methods inherited from Decidim::Command

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

Constructor Details

#initialize(form) ⇒ CreateResource

Initializes the command.

Parameters:

  • form (Decidim::Form)

    the form object to create the resource.



10
11
12
# File 'decidim-core/lib/decidim/commands/create_resource.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

Creates the result if valid.

Broadcasts :ok if successful, :invalid otherwise.



17
18
19
20
21
22
23
24
25
26
27
# File 'decidim-core/lib/decidim/commands/create_resource.rb', line 17

def call
  return broadcast(:invalid) if invalid?

  perform!
  broadcast(:ok, resource)
rescue ActiveRecord::RecordInvalid
  add_file_attribute_errors!
  broadcast(:invalid)
rescue Decidim::Commands::HookError
  broadcast(:invalid)
end