Class: Decidim::DummyResources::CreateDummyResource

Inherits:
Command
  • Object
show all
Includes:
GalleryMethods
Defined in:
decidim-dev/app/commands/decidim/dummy_resources/create_dummy_resource.rb

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(form) ⇒ CreateDummyResource

Returns a new instance of CreateDummyResource.



8
9
10
# File 'decidim-dev/app/commands/decidim/dummy_resources/create_dummy_resource.rb', line 8

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 dummy_resource if valid.

Broadcasts :ok if successful, :invalid otherwise.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'decidim-dev/app/commands/decidim/dummy_resources/create_dummy_resource.rb', line 15

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

  if process_gallery?
    build_gallery
    return broadcast(:invalid) if gallery_invalid?
  end

  transaction do
    create_dummy_resource
    create_gallery if process_gallery?
  end

  broadcast(:ok)
end