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.(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
|