Class: Decidim::DummyResources::CreateDummyResource

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

Instance Method Summary collapse

Constructor Details

#initialize(form) ⇒ CreateDummyResource

Returns a new instance of CreateDummyResource.


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

def initialize(form)
  @form = form
end

Instance Method Details

#callObject

Creates the dummy_resource if valid.

Broadcasts :ok if successful, :invalid otherwise.


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

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