Module: ImportFile
- Extended by:
- ActiveSupport::Concern
- Included in:
- UserImportFile
- Defined in:
- app/models/concerns/import_file.rb
Class Method Summary collapse
-
.expire ⇒ Object
失敗したインポート処理を一括削除します。.
Instance Method Summary collapse
-
#convert_encoding(line) ⇒ Object
インポートするファイルの文字コードをUTF-8に変換します。.
- #import_start ⇒ Object
-
#send_message(mailer) ⇒ Object
インポート完了時のメッセージを送信します。.
Class Method Details
.expire ⇒ Object
失敗したインポート処理を一括削除します。
5 6 7 8 9 |
# File 'app/models/concerns/import_file.rb', line 5 def self.expire self.stucked.find_each do |file| file.destroy end end |
Instance Method Details
#convert_encoding(line) ⇒ Object
インポートするファイルの文字コードをUTF-8に変換します。
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/concerns/import_file.rb', line 26 def convert_encoding(line) if defined?(CharlockHolmes::EncodingDetector) begin case user_encoding when 'auto_detect' encoding = CharlockHolmes::EncodingDetector.detect(line)[:encoding] when nil encoding = CharlockHolmes::EncodingDetector.detect(line)[:encoding] else encoding = user_encoding end line.encode('UTF-8', encoding, universal_newline: true) rescue StandardError nkf_encode(line) end else nkf_encode(line) end end |
#import_start ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/concerns/import_file.rb', line 11 def import_start case edit_mode when 'create' import when 'update' modify when 'destroy' remove else import end end |
#send_message(mailer) ⇒ Object
インポート完了時のメッセージを送信します。
47 48 49 50 51 52 53 54 55 |
# File 'app/models/concerns/import_file.rb', line 47 def (mailer) sender = User.find(1) = Message.create!( recipient: user.username, sender: sender, body: mailer.body.raw_source, subject: mailer.subject ) end |