Class: UserExportFile

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

Instance Method Summary collapse

Methods included from ExportFile

included

Instance Method Details

#export!Object

エクスポートの処理を実行します。



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

def export!
  transition_to!(:started)
  tempfile = Tempfile.new(['user_export_file_', '.txt'])
  file = User.export(format: :txt)
  tempfile.puts(file)
  tempfile.close
  self.user_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/user_export_file.rb', line 23

def state_machine
  UserExportFileStateMachine.new(self, transition_class: UserExportFileTransition)
end