Class: Decidim::Admin::CreateImport

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(form) ⇒ CreateImport

Returns a new instance of CreateImport.


6
7
8
# File 'decidim-admin/app/commands/decidim/admin/create_import.rb', line 6

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 Attribute Details

#formObject (readonly)

Returns the value of attribute form.


25
26
27
# File 'decidim-admin/app/commands/decidim/admin/create_import.rb', line 25

def form
  @form
end

Instance Method Details

#callObject


10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'decidim-admin/app/commands/decidim/admin/create_import.rb', line 10

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

  imported_data = form.importer.prepare
  transaction do
    form.importer.import!

    broadcast(:ok, imported_data)
  rescue StandardError
    # Something went wrong with import/finish
    broadcast(:invalid)
    raise ActiveRecord::Rollback
  end
end