Class: Decidim::Surveys::DataImporter

Inherits:
Importers::Importer show all
Defined in:
decidim-surveys/app/serializers/decidim/surveys/data_importer.rb

Overview

Importer for Surveys specific data (this is, its questionnaire).

Instance Method Summary collapse

Constructor Details

#initialize(component) ⇒ DataImporter

Returns a new instance of DataImporter.



7
8
9
# File 'decidim-surveys/app/serializers/decidim/surveys/data_importer.rb', line 7

def initialize(component)
  @component = component
end

Instance Method Details

#import(serialized, user) ⇒ Object

Public: Creates a new Decidim::Surveys::Survey and Decidim::Forms::Questionnaire associated to the given component

for each serialized survey object.

It imports the whole tree of Survey->Questionnaire->questions->answer_options.

serialized - The Hash of attributes for the Questionnaire and its relations. user - The user that is performing this action

Returns the ser.



19
20
21
22
23
24
25
26
# File 'decidim-surveys/app/serializers/decidim/surveys/data_importer.rb', line 19

def import(serialized, user)
  ActiveRecord::Base.transaction do
    # we duplicate so that we can delete without affecting the received Hash
    serialized.dup.collect do |serialized_survey|
      import_survey(serialized_survey, user)
    end
  end
end