Class: ResourceExportFile

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ExportFile, Statesman::Adapters::ActiveRecordQueries
Defined in:
app/models/resource_export_file.rb

Instance Method Summary collapse

Instance Method Details

#export!Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/resource_export_file.rb', line 30

def export!
  transition_to!(:started)
  role_name = user.try(:role).try(:name)
  tempfile = Tempfile.new(['resource_export_file_', '.txt'])
  tempfile.puts(Manifestation.csv_header(role_name, col_sep: "\t"))
  Manifestation.find_each do |manifestation|
    tempfile.puts(manifestation.to_csv(format: :txt, role: role_name))
  end
  tempfile.close
  self.resource_export = File.new(tempfile.path, "r")
  if save
    send_message
  end
  transition_to!(:completed)
rescue => e
  transition_to!(:failed)
  raise e
end

#state_machineObject



23
24
25
# File 'app/models/resource_export_file.rb', line 23

def state_machine
  ResourceExportFileStateMachine.new(self, transition_class: ResourceExportFileTransition)
end