Class: UserExportFile

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ExportFile

#send_message

Class Method Details

.initial_stateObject



51
52
53
# File 'app/models/user_export_file.rb', line 51

def self.initial_state
  :pending
end

.transition_classObject



47
48
49
# File 'app/models/user_export_file.rb', line 47

def self.transition_class
  UserExportFileTransition
end

Instance Method Details

#export!Object

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



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

def export!
  transition_to!(:started)
  tempfile = Tempfile.new(['user_export_file_', '.txt'])
  file = User.export(format: :text)
  tempfile.puts(file)
  tempfile.close
  self.user_export = File.new(tempfile.path, 'r')
  save!
  transition_to!(:completed)
  mailer = UserExportMailer.completed(self)
  send_message(mailer)
rescue => e
  transition_to!(:failed)
  mailer = UserExportMailer.failed(self)
  raise e
end

#state_machineObject



22
23
24
# File 'app/models/user_export_file.rb', line 22

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