Skip to content

Commit 5c8b797

Browse files
authored
Merge pull request #59 from amatsuda/indentation_width
rubocop --only Layout/IndentationWidth --autocorrect
2 parents f22dc59 + 8c369b9 commit 5c8b797

File tree

6 files changed

+93
-93
lines changed

6 files changed

+93
-93
lines changed

app/controllers/messages_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def search(query)
4040
# %> and <-> are defined by pg_trgm.
4141
# https://www.postgresql.org/docs/17/pgtrgm.html
4242
message_where = if Rails.env.production?
43-
Message.where('body %> ? AND list_id IN (?)', query, list_ids)
44-
.order(Arel.sql('body <-> ?', query))
43+
Message.where('body %> ? AND list_id IN (?)', query, list_ids)
44+
.order(Arel.sql('body <-> ?', query))
4545
else
4646
Message.where('body LIKE ? AND list_id IN (?)', "%#{query}%", list_ids)
4747
end

app/helpers/messages_helper.rb

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
module MessagesHelper
2-
def without_list_prefix(subject)
3-
subject.sub(/^\[.+?\]\s*/, '')
4-
end
2+
def without_list_prefix(subject)
3+
subject.sub(/^\[.+?\]\s*/, '')
4+
end
55

6-
MARGIN = 50
7-
def search_snippet(body, keyword)
8-
snippet = ''
6+
MARGIN = 50
7+
def search_snippet(body, keyword)
8+
snippet = ''
99

10-
offset = 0
11-
while (i = body.index(keyword, offset))
12-
start = [i - MARGIN, offset].max
13-
len = keyword.length + MARGIN
14-
snippet += body[start, len]
15-
offset = start + len
16-
end
10+
offset = 0
11+
while (i = body.index(keyword, offset))
12+
start = [i - MARGIN, offset].max
13+
len = keyword.length + MARGIN
14+
snippet += body[start, len]
15+
offset = start + len
16+
end
1717

18-
if snippet.empty?
19-
return body[0, MARGIN * 2]
20-
else
21-
snippet
22-
end
23-
end
18+
if snippet.empty?
19+
return body[0, MARGIN * 2]
20+
else
21+
snippet
22+
end
23+
end
2424
end

app/models/list.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
class List
2-
def initialize(name, id)
3-
@name = name
4-
@id = id
5-
end
6-
attr_reader :name, :id
2+
def initialize(name, id)
3+
@name = name
4+
@id = id
5+
end
6+
attr_reader :name, :id
77

88
# Ordered by the established dates. ruby-list was started in 1995.
9-
LISTS = [
10-
List.new('ruby-list', 1),
11-
List.new('ruby-dev', 2),
12-
List.new('ruby-core', 3),
13-
List.new('ruby-talk', 4),
14-
]
9+
LISTS = [
10+
List.new('ruby-list', 1),
11+
List.new('ruby-dev', 2),
12+
List.new('ruby-core', 3),
13+
List.new('ruby-talk', 4),
14+
]
1515

16-
def self.find_by_name(name)
17-
LISTS.find { |list| list.name == name }
18-
end
16+
def self.find_by_name(name)
17+
LISTS.find { |list| list.name == name }
18+
end
1919

20-
def self.find_by_id(id)
21-
LISTS.find { |list| list.id == id }
22-
end
20+
def self.find_by_id(id)
21+
LISTS.find { |list| list.id == id }
22+
end
2323
end

app/models/message.rb

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,50 @@ class Message < ApplicationRecord
88
# but I don't want to make this column.
99
# https://blade.ruby-lang.org/ruby-talk/1 is JST.
1010
# https://blade.ruby-lang.org/ruby-talk/410000 is not.
11-
self.skip_time_zone_conversion_for_attributes = [:published_at]
11+
self.skip_time_zone_conversion_for_attributes = [:published_at]
1212

13-
def self.from_s3(list_name, list_seq, s3_client = Aws::S3::Client.new(region: BLADE_BUCKET_REGION))
14-
obj = s3_client.get_object(bucket: BLADE_BUCKET_NAME, key: "#{list_name}/#{list_seq}")
13+
def self.from_s3(list_name, list_seq, s3_client = Aws::S3::Client.new(region: BLADE_BUCKET_REGION))
14+
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
20-
end
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+
end
2121

22-
def self.from_string(str)
23-
# There are a few hacks to import messages from blade.ruby-lang.org's
24-
# S3 bucket.
22+
def self.from_string(str)
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.
28-
headers_str, body = str.b.split(/\n\n/, 2)
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+
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-
)
45-
end
39+
self.new(
40+
body: Kconv.toutf8(body),
41+
subject: headers['Subject'],
42+
from: headers['From'],
43+
published_at: published_at,
44+
)
45+
end
4646

47-
def reload_from_s3(s3_client = Aws::S3::Client.new(region: BLADE_BUCKET_REGION))
48-
m = Message.from_s3(List.find_by_id(self.list_id).name, self.list_seq, s3_client)
47+
def reload_from_s3(s3_client = Aws::S3::Client.new(region: BLADE_BUCKET_REGION))
48+
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
56-
end
55+
m
56+
end
5757
end

db/migrate/20251010175059_create_active_storage_variant_records.active_storage.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ def change
1414
end
1515

1616
private
17-
def primary_key_type
18-
config = Rails.configuration.generators
19-
config.options[config.orm][:primary_key_type] || :primary_key
20-
end
17+
def primary_key_type
18+
config = Rails.configuration.generators
19+
config.options[config.orm][:primary_key_type] || :primary_key
20+
end
2121

22-
def blobs_primary_key_type
23-
pkey_name = connection.primary_key(:active_storage_blobs)
24-
pkey_column = connection.columns(:active_storage_blobs).find { |c| c.name == pkey_name }
25-
pkey_column.bigint? ? :bigint : pkey_column.type
26-
end
22+
def blobs_primary_key_type
23+
pkey_name = connection.primary_key(:active_storage_blobs)
24+
pkey_column = connection.columns(:active_storage_blobs).find { |c| c.name == pkey_name }
25+
pkey_column.bigint? ? :bigint : pkey_column.type
26+
end
2727
end

import.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22

33
params = {}
44
OptionParser.new do |opts|
5-
opts.on('--list LIST')
5+
opts.on('--list LIST')
66
opts.on('--from FROM', Integer)
77
opts.on('--to TO', Integer)
88
end.parse!(into: params)
99

1010
list = params[:list]
1111

1212
(params[:from]..params[:to]).each do |seq|
13-
begin
14-
message = Message.from_s3(list, seq)
15-
message.save
16-
rescue ActiveRecord::RecordNotUnique
17-
STDERR.puts("#{list}:#{seq} already exists in Postgres")
18-
rescue Aws::S3::Errors::NoSuchKey
19-
STDERR.puts("#{list}:#{seq} doesn't exist in S3")
20-
rescue StandardError => e
21-
STDERR.puts("failed to import #{list}:#{seq}: #{e}")
22-
end
13+
begin
14+
message = Message.from_s3(list, seq)
15+
message.save
16+
rescue ActiveRecord::RecordNotUnique
17+
STDERR.puts("#{list}:#{seq} already exists in Postgres")
18+
rescue Aws::S3::Errors::NoSuchKey
19+
STDERR.puts("#{list}:#{seq} doesn't exist in S3")
20+
rescue StandardError => e
21+
STDERR.puts("failed to import #{list}:#{seq}: #{e}")
22+
end
2323
end

0 commit comments

Comments
 (0)