Skip to content

Commit 48564c6

Browse files
denis1011101claude
andcommitted
chore: lean on Ruby 4 for fallback chains and the bot token
The app runs on Ruby 4.0.6 in development and in production, so a few places can now say what they mean. Fallback chains and multi-part conditions used trailing `||` / `&&`, which pushed every alternative one indent deeper than the one before it. Ruby 4 continues a line when the operator opens the next one, so the alternatives in LocaleDetector, the wallchart banner check, the Telegram display name and the duplicate-match lookup now line up in one column. Telegram::Poller holds the bot token in an instance variable, so any log line or error message that inspected the poller printed the token with it. It now lists only @offset in instance_variables_to_inspect. A leading "@" in a Telegram handle is trimmed by String#lstrip with a selector instead of an anchored regexp. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent cbe7e14 commit 48564c6

7 files changed

Lines changed: 36 additions & 18 deletions

File tree

app/helpers/application_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def wallchart_banner_active?
4141
# that kicks off within the promo season. The start-date bound keeps the promo
4242
# copy off unrelated matches featured after the tournament.
4343
def wallchart_final?(featured_match)
44-
featured_match.active? &&
45-
featured_match.status != "finished" &&
46-
featured_match.starts_at.to_date <= WALLCHART_BANNER_UNTIL
44+
featured_match.active?
45+
&& featured_match.status != "finished"
46+
&& featured_match.starts_at.to_date <= WALLCHART_BANNER_UNTIL
4747
end
4848

4949
# Accessible label for the banner countdown region, matching what's shown:

app/models/court.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def build_contact_link(value)
179179
if normalized_value.match?(/\Ahttps?:\/\//)
180180
normalized_value
181181
else
182-
username = normalized_value.sub(/\A@/, "")
182+
username = normalized_value.lstrip("@")
183183
username.present? ? "https://t.me/#{username}" : nil
184184
end
185185
when "whatsapp"

app/services/locale_detector.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ def initialize(request, cookies)
1414
end
1515

1616
def call
17-
subdomain_locale ||
18-
cookie_locale ||
19-
country_locale ||
20-
accept_language_locale ||
21-
default_locale
17+
subdomain_locale
18+
|| cookie_locale
19+
|| country_locale
20+
|| accept_language_locale
21+
|| default_locale
2222
end
2323

2424
private

app/services/player_statistics/upsert_match_for_game_service.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,19 @@ def find_or_init_manual_match(played_date)
8484

8585
scope.to_a.find do |match|
8686
stats = match.stats.to_h
87-
normalize_ids(stats["team_a_ids"]) == team_a_ids &&
88-
normalize_ids(stats["team_b_ids"]) == team_b_ids &&
89-
normalize_guest_names(stats["team_a_guest_names"]) == normalize_guest_names(@stats["team_a_guest_names"]) &&
90-
normalize_guest_names(stats["team_b_guest_names"]) == normalize_guest_names(@stats["team_b_guest_names"])
87+
normalize_ids(stats["team_a_ids"]) == team_a_ids
88+
&& normalize_ids(stats["team_b_ids"]) == team_b_ids
89+
&& normalize_guest_names(stats["team_a_guest_names"]) == normalize_guest_names(@stats["team_a_guest_names"])
90+
&& normalize_guest_names(stats["team_b_guest_names"]) == normalize_guest_names(@stats["team_b_guest_names"])
9191
end
9292
else
9393
opponent_id = @opponent&.id || normalize_ids(@stats["opponent_ids"]).first
9494
opponent_guest_names = normalize_guest_names(opponent_guest_names_for_stats(@stats))
9595

9696
scope.to_a.find do |match|
9797
stats = match.stats.to_h
98-
(opponent_id.present? && (match.opponent_id == opponent_id || normalize_ids(stats["opponent_ids"]).first == opponent_id)) ||
99-
(opponent_guest_names.any? && normalize_guest_names(opponent_guest_names_for_stats(stats)) == opponent_guest_names)
98+
(opponent_id.present? && (match.opponent_id == opponent_id || normalize_ids(stats["opponent_ids"]).first == opponent_id))
99+
|| (opponent_guest_names.any? && normalize_guest_names(opponent_guest_names_for_stats(stats)) == opponent_guest_names)
100100
end
101101
end
102102

app/services/telegram/helpers/user_lookup.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def self.display_name(user, fallback: "User")
2626
elsif user.respond_to?(:username) && user.username.to_s.strip.present?
2727
"@#{user.username.to_s.strip.delete_prefix('@')}"
2828
else
29-
user.name.to_s.strip.presence ||
30-
(user.respond_to?(:email) && user.email.to_s.strip.presence) ||
31-
fallback
29+
user.name.to_s.strip.presence
30+
|| (user.respond_to?(:email) && user.email.to_s.strip.presence)
31+
|| fallback
3232
end
3333
end
3434
end

app/services/telegram/poller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ def initialize(token = ENV["TELEGRAM_BOT_TOKEN"], logger = Rails.logger)
1111
raise "TELEGRAM_BOT_TOKEN not set" if @token.empty?
1212
end
1313

14+
# Поллер попадает в логи и в сообщения об ошибках целиком, поэтому в inspect
15+
# оставляем только позицию в очереди обновлений — токен бота светить нельзя.
16+
private def instance_variables_to_inspect = [ :@offset ]
17+
1418
# Single poll iteration: fetch updates and dispatch to UpdateService
1519
def run_once(poll_interval: 0.5)
1620
updates = fetch_updates(@offset)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require "test_helper"
2+
3+
class Telegram::PollerTest < ActiveSupport::TestCase
4+
test "inspect keeps the bot token out of logs and error messages" do
5+
poller = Telegram::Poller.new("123456:super-secret-token")
6+
7+
assert_not_includes poller.inspect, "super-secret-token"
8+
assert_includes poller.inspect, "@offset"
9+
end
10+
11+
test "refuses to start without a token" do
12+
assert_raises(RuntimeError) { Telegram::Poller.new("") }
13+
end
14+
end

0 commit comments

Comments
 (0)