Class: UserExportFile
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- UserExportFile
- Includes:
- ExportFile, Statesman::Adapters::ActiveRecordQueries
- Defined in:
- app/models/user_export_file.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#export! ⇒ Object
エクスポートの処理を実行します。.
- #state_machine ⇒ Object
Methods included from ExportFile
Class Method Details
.initial_state ⇒ Object
51 52 53 |
# File 'app/models/user_export_file.rb', line 51 def self.initial_state :pending end |
.transition_class ⇒ Object
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) (mailer) rescue => e transition_to!(:failed) mailer = UserExportMailer.failed(self) raise e end |
#state_machine ⇒ Object
22 23 24 |
# File 'app/models/user_export_file.rb', line 22 def state_machine UserExportFileStateMachine.new(self, transition_class: UserExportFileTransition) end |