Class: ResourceExportFile

Inherits:
ApplicationRecord
  • Object
show all
Includes:
ExportFile, Statesman::Adapters::ActiveRecordQueries
Defined in:
app/models/resource_export_file.rb,
app/models2/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)
  tsv = Manifestation.export(role: role_name)
  file = StringIO.new(tsv)
  file.class.class_eval { attr_accessor :original_filename, :content_type }
  file.original_filename =  'resource_export.txt'
  self.resource_export = file
  save!
  transition_to!(:completed)
  mailer = ResourceExportMailer.completed(self)
  send_message(mailer)
rescue => e
  transition_to!(:failed)
  mailer = ResourceExportMailer.failed(self)
  send_message(mailer)
  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