Class: Decidim::Commands::UpdateResource

Inherits:
Decidim::Command show all
Includes:
ResourceHandler
Defined in:
lib/decidim/commands/update_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, resource) ⇒ UpdateResource

Initializes the command.

Parameters:

  • form (Decidim::Form)

    the form object to update the resource.

  • resource (Decidim::Resource)

    the resource to update.



12
13
14
15
# File 'lib/decidim/commands/update_resource.rb', line 12

def initialize(form, resource)
  @form = form
  @resource = resource
end

Dynamic Method Handling

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

Instance Method Details

#callObject

Updates the resource if valid.

Broadcasts :ok if successful, :invalid otherwise.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/decidim/commands/update_resource.rb', line 20

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