Class: EventExportFile

Inherits:
ApplicationRecord
  • Object
show all
Includes:
ExportFile, Statesman::Adapters::ActiveRecordQueries
Defined in:
app/models/event_export_file.rb

Instance Method Summary collapse

Instance Method Details

#export!Object



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

def export!
  role_name = user.try(:role).try(:name)
  tsv = Event.export(role: role_name)

  EventExportFile.transaction do
    transition_to!(:started)
    role_name = user.try(:role).try(:name)
    self.event_export = StringIO.new(tsv)
    self.event_export.instance_write(:filename, "event_export.txt")
    save!
    transition_to!(:completed)
  end
  mailer = EventExportMailer.completed(self)
  send_message(mailer)
rescue => e
  transition_to!(:failed)
  mailer = EventExportMailer.failed(self)
  send_message(mailer)
  raise e
end

#state_machineObject



21
22
23
# File 'app/models/event_export_file.rb', line 21

def state_machine
  EventExportFileStateMachine.new(self, transition_class: EventExportFileTransition)
end