Class: Decidim::Admin::CreateImport

Inherits:
Command
  • Object
show all
Defined in:
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 '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.



25
26
27
# File '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 '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