Skip to content

Commit 535c254

Browse files
committed
refactor: 非アクティブ判定の閾値をDojoモデルに定数化
- INACTIVE_THRESHOLD = 1.year をDojoモデルに定義 - メンテナンス性向上(閾値変更が容易に) - ビューでは Time.current.prev_year の代わりに定数を使用 - Claudeからのフィードバックを適用
1 parent f0166c5 commit 535c254

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

app/controllers/dojos_controller.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ def show
109109
# GET /dojos/activity
110110
# 道場の活動状況を表示(旧 /events/latest から移行)
111111
def activity
112+
# ビューで使用するための閾値をインスタンス変数に設定(モデルから取得)
113+
@inactive_threshold = Dojo::INACTIVE_THRESHOLD
114+
112115
@latest_event_by_dojos = []
113116
Dojo.active.each do |dojo|
114117
link_in_note = dojo.note.match(URI.regexp)

app/models/dojo.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ class Dojo < ApplicationRecord
55
NUM_OF_TOTAL_EVENTS = "10,000"
66
NUM_OF_TOTAL_NINJAS = "62,000"
77
DOJO_INFO_YAML_PATH = Rails.root.join('db', 'dojos.yml')
8+
9+
# 1年以上イベント開催していない道場を判定する閾値
10+
INACTIVE_THRESHOLD = 1.year
811

912
belongs_to :prefecture
1013
has_many :dojo_event_services, dependent: :destroy

app/views/dojos/activity.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@
7474
<small>
7575
<% if dojo[:latest_event_at] %>
7676
<!-- イベント履歴がある場合 -->
77-
<% expired = dojo[:latest_event_at] <= Time.current.prev_year && !dojo[:note].include?('Active') %>
77+
<% expired = dojo[:latest_event_at] <= Time.current - @inactive_threshold && !dojo[:note].include?('Active') %>
7878
<span class="<%= 'expired' if expired %>">
7979
<%= link_to dojo[:latest_event_at].strftime("%Y-%m-%d"), dojo[:latest_event_url] %>
8080
</span>
8181
<% elsif dojo[:note_date] %>
8282
<!-- note内に日付がある場合 -->
83-
<% expired = dojo[:note_date] <= Time.current.prev_year && !dojo[:note].include?('Active') %>
83+
<% expired = dojo[:note_date] <= Time.current - @inactive_threshold && !dojo[:note].include?('Active') %>
8484
<span class="<%= 'expired' if expired %>">
8585
<% if dojo[:note_link] %>
8686
<%= link_to dojo[:note_date].strftime("%Y-%m-%d"), dojo[:note_link] %>

0 commit comments

Comments
 (0)