Class: Decidim::Admin::CreateImport

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Instance Attribute Details

#formObject (readonly)

Returns the value of attribute form


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

def form
  @form
end

Instance Method Details

#callObject


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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!

    return broadcast(:ok, imported_data)
  rescue StandardError
    raise ActiveRecord::Rollback
  end

  # Something went wrong with import/finish
  broadcast(:invalid)
end