Skip to content

Commit f1943f5

Browse files
committed
<<
1 parent 9c5d007 commit f1943f5

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

app/models/message.rb

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,54 @@
44
require 'kconv'
55

66
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.
1111
self.skip_time_zone_conversion_for_attributes = [:published_at]
1212

1313
def self.from_s3(list_name, list_seq, s3_client = Aws::S3::Client.new(region: BLADE_BUCKET_REGION))
1414
obj = s3_client.get_object(bucket: BLADE_BUCKET_NAME, key: "#{list_name}/#{list_seq}")
1515

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
2020
end
2121

2222
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.
2525

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.
2828
headers_str, body = str.b.split(/\n\n/, 2)
2929

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/, '')
3232

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
3636

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')
3838

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+
)
4545
end
4646

4747
def reload_from_s3(s3_client = Aws::S3::Client.new(region: BLADE_BUCKET_REGION))
4848
m = Message.from_s3(List.find_by_id(self.list_id).name, self.list_seq, s3_client)
4949

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
5454

55-
m
55+
m
5656
end
5757
end

import.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
params = {}
44
OptionParser.new do |opts|
55
opts.on('--list LIST')
6-
opts.on('--from FROM', Integer)
7-
opts.on('--to TO', Integer)
6+
opts.on('--from FROM', Integer)
7+
opts.on('--to TO', Integer)
88
end.parse!(into: params)
99

1010
list = params[:list]

0 commit comments

Comments
 (0)