Skip to content

Commit 68e0b28

Browse files
committed
Prefer AR compatible API: List.find(2)
1 parent b5a5b42 commit 68e0b28

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

app/models/list.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ def initialize(name, id)
1313
List.new('ruby-talk', 4),
1414
]
1515

16-
def self.find_by_name(name)
17-
LISTS.find { |list| list.name == name }
18-
end
16+
class << self
17+
def find_by_name(name)
18+
List::LISTS.find { |list| list.name == name }
19+
end
20+
21+
def find_by_id(id)
22+
List::LISTS.find { |list| list.id == id }
23+
end
1924

20-
def self.find_by_id(id)
21-
LISTS.find { |list| list.id == id }
25+
alias find find_by_id
2226
end
2327
end

app/models/message.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ def from_string(str)
127127
end
128128

129129
def list
130-
@list ||= List.find_by_id(list_id)
130+
@list ||= List.find(list_id)
131131
end
132132

133133
def count_recursively(count = 0)
134134
count + 1 + (children&.sum(&:count_recursively) || 0)
135135
end
136136

137137
def reload_from_s3(s3_client = Aws::S3::Client.new(region: BLADE_BUCKET_REGION))
138-
m = Message.from_s3(List.find_by_id(self.list_id).name, self.list_seq, s3_client)
138+
m = Message.from_s3(List.find(self.list_id).name, self.list_seq, s3_client)
139139

140140
self.body = m.body
141141
self.subject = m.subject

app/views/messages/search.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
<% @messages.each do |message| %>
2929
<div class="search-result">
30-
<% list_name = List.find_by_id(message.list_id).name %>
30+
<% list_name = List.find(message.list_id).name %>
3131
<h2 class="subject">
3232
<span class="prefix"><%= list_name %>:<%= message.list_seq %></span>
3333
<%= link_to without_list_prefix(message.subject), "/#{list_name}/#{message.list_seq}" %>

0 commit comments

Comments
 (0)