Skip to content

Commit 61b286b

Browse files
committed
Change method name from exists? to exist? to match File#exist?
1 parent 0aaeb06 commit 61b286b

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

app/controllers/docs_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def kata
1515

1616
def show
1717
@doc = Document.new(params[:id])
18-
redirect_to root_url unless @doc.exists?
18+
redirect_to root_url unless @doc.exist?
1919

2020
if @doc.content.include? "NUM_OF_"
2121
@doc.content.gsub! "{{ NUM_OF_JAPAN_DOJOS }}", Dojo.active_dojos_count.to_s

app/models/document.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,21 @@ def url
5555
"#{URL_PATH}/#{self.filename}"
5656
end
5757

58-
def exists?
58+
def exist?
5959
return false if path.include? "\u0000"
6060
Document.all.map(&:filename).include?(filename)
6161
end
6262

6363
def title
64-
return '' unless self.exists?
64+
return '' unless self.exist?
6565
@title ||=
6666
ActionController::Base.helpers.strip_tags(
6767
Kramdown::Document.new(self.get_first_paragraph, input: 'GFM').to_html
6868
).strip
6969
end
7070

7171
def description
72-
return '' unless self.exists?
72+
return '' unless self.exist?
7373
@desc ||=
7474
ActionController::Base.helpers.strip_tags(
7575
Kramdown::Document.new(self.get_second_paragraph, input: 'GFM').to_html
@@ -80,7 +80,7 @@ def description=(text)
8080
end
8181

8282
def content
83-
@content ||= self.exists? ? File.read(self.path) : ''
83+
@content ||= self.exist? ? File.read(self.path) : ''
8484
end
8585

8686
private

app/models/podcast.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def path
1818
"#{DIR_PATH}/#{id}.md"
1919
end
2020

21-
def exists?(offset: 0)
21+
def exist?(offset: 0)
2222
return false if self.path.include?("\u0000")
2323
return false if (self.id + offset).zero?
2424
File.exist?("#{DIR_PATH}/#{id + offset}.md")

app/views/podcasts/_navigation.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div style="display: table; font-weight: bolder; width: 100%; padding: 10px 10px; background-color:#3870c4;">
22
<p class="nav prev">
3-
<% if @episode.exists?(offset: -1) %>
3+
<% if @episode.exist?(offset: -1) %>
44
<%= link_to podcast_path(@episode.id - 1), title: '前のエピソードを見る' do %>
55
&laquo; prev
66
<% end %>
@@ -12,7 +12,7 @@
1212
<%= link_to '目次に戻る'.html_safe, podcasts_path %>
1313
</p>
1414
<p class="nav next">
15-
<% if @episode.exists?(offset: +1) %>
15+
<% if @episode.exist?(offset: +1) %>
1616
<%= link_to podcast_path(@episode.id + 1), title: '次のエピソードを見る' do %>
1717
next &raquo;
1818
<% end %>

spec/models/podcast_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
expect(@podcast.path).to eq("public/podcasts/#{@podcast.id}.md")
1111
end
1212

13-
describe 'exists?(offset: 0)' do
13+
describe 'exist?(offset: 0)' do
1414
it '\u0000 を含む ⇒ false' do
1515
allow(@podcast).to receive(:path) { "public/podcasts/\u0000" }
1616

17-
expect(@podcast.exists?).to eq(false)
17+
expect(@podcast.exist?).to eq(false)
1818
end
1919

2020
context 'offset 省略' do
@@ -25,11 +25,11 @@
2525
it 'ファイルあり ⇒ true' do
2626
allow(File).to receive(:exist?).with("public/podcasts/#{@podcast.id}.md") { true }
2727

28-
expect(@podcast.exists?).to eq(true)
28+
expect(@podcast.exist?).to eq(true)
2929
end
3030

3131
it 'ファイルなし ⇒ false' do
32-
expect(@podcast.exists?).to eq(false)
32+
expect(@podcast.exist?).to eq(false)
3333
end
3434
end
3535

@@ -41,11 +41,11 @@
4141
it 'ファイルあり ⇒ true' do
4242
allow(File).to receive(:exist?).with("public/podcasts/#{@podcast.id + 1}.md") { true }
4343

44-
expect(@podcast.exists?(offset: 1)).to eq(true)
44+
expect(@podcast.exist?(offset: 1)).to eq(true)
4545
end
4646

4747
it 'ファイルなし ⇒ false' do
48-
expect(@podcast.exists?(offset: 1)).to eq(false)
48+
expect(@podcast.exist?(offset: 1)).to eq(false)
4949
end
5050
end
5151
end

0 commit comments

Comments
 (0)