|
4 | 4 | require 'kconv' |
5 | 5 |
|
6 | 6 | class Message < ApplicationRecord |
7 | | - # Not really sure we will utlize this configuration, |
8 | | - # but I don't want to make this column. |
9 | | - # https://blade.ruby-lang.org/ruby-talk/1 is JST. |
10 | | - # https://blade.ruby-lang.org/ruby-talk/410000 is not. |
| 7 | + # Not really sure we will utlize this configuration, |
| 8 | + # but I don't want to make this column. |
| 9 | + # https://blade.ruby-lang.org/ruby-talk/1 is JST. |
| 10 | + # https://blade.ruby-lang.org/ruby-talk/410000 is not. |
11 | 11 | self.skip_time_zone_conversion_for_attributes = [:published_at] |
12 | 12 |
|
13 | 13 | def self.from_s3(list_name, list_seq, s3_client = Aws::S3::Client.new(region: BLADE_BUCKET_REGION)) |
14 | 14 | obj = s3_client.get_object(bucket: BLADE_BUCKET_NAME, key: "#{list_name}/#{list_seq}") |
15 | 15 |
|
16 | | - m = self.from_string(obj.body.read) |
17 | | - m.list_id = List.find_by_name(list_name).id |
18 | | - m.list_seq = list_seq |
19 | | - m |
| 16 | + m = self.from_string(obj.body.read) |
| 17 | + m.list_id = List.find_by_name(list_name).id |
| 18 | + m.list_seq = list_seq |
| 19 | + m |
20 | 20 | end |
21 | 21 |
|
22 | 22 | def self.from_string(str) |
23 | | - # There are a few hacks to import messages from blade.ruby-lang.org's |
24 | | - # S3 bucket. |
| 23 | + # There are a few hacks to import messages from blade.ruby-lang.org's |
| 24 | + # S3 bucket. |
25 | 25 |
|
26 | | - # Need to call String#b. There are messages that have headers in non-UTF8, |
27 | | - # but the body is in UTF-8, such as ruby-list:2882. |
| 26 | + # Need to call String#b. There are messages that have headers in non-UTF8, |
| 27 | + # but the body is in UTF-8, such as ruby-list:2882. |
28 | 28 | headers_str, body = str.b.split(/\n\n/, 2) |
29 | 29 |
|
30 | | - # ruby-list:2840 doesn't have a proper From header. |
31 | | - headers_str = Kconv.toutf8(headers_str).gsub(/\r\n/, '') |
| 30 | + # ruby-list:2840 doesn't have a proper From header. |
| 31 | + headers_str = Kconv.toutf8(headers_str).gsub(/\r\n/, '') |
32 | 32 |
|
33 | | - headers = headers_str.split(/\n/).map { |line| |
34 | | - line.split(/:\s+/, 2) |
35 | | - }.to_h |
| 33 | + headers = headers_str.split(/\n/).map { |line| |
| 34 | + line.split(/:\s+/, 2) |
| 35 | + }.to_h |
36 | 36 |
|
37 | | - published_at = DateTime.strptime(headers['Date'], '%Y-%m-%dT%H:%M:%S%:z') |
| 37 | + published_at = DateTime.strptime(headers['Date'], '%Y-%m-%dT%H:%M:%S%:z') |
38 | 38 |
|
39 | | - self.new( |
40 | | - body: Kconv.toutf8(body), |
41 | | - subject: headers['Subject'], |
42 | | - from: headers['From'], |
43 | | - published_at: published_at, |
44 | | - ) |
| 39 | + self.new( |
| 40 | + body: Kconv.toutf8(body), |
| 41 | + subject: headers['Subject'], |
| 42 | + from: headers['From'], |
| 43 | + published_at: published_at, |
| 44 | + ) |
45 | 45 | end |
46 | 46 |
|
47 | 47 | def reload_from_s3(s3_client = Aws::S3::Client.new(region: BLADE_BUCKET_REGION)) |
48 | 48 | m = Message.from_s3(List.find_by_id(self.list_id).name, self.list_seq, s3_client) |
49 | 49 |
|
50 | | - self.body = m.body |
51 | | - self.subject = m.subject |
52 | | - self.from = from |
53 | | - self.published_at = m.published_at |
| 50 | + self.body = m.body |
| 51 | + self.subject = m.subject |
| 52 | + self.from = from |
| 53 | + self.published_at = m.published_at |
54 | 54 |
|
55 | | - m |
| 55 | + m |
56 | 56 | end |
57 | 57 | end |
0 commit comments