jumbotron 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/models/jumbotron/public.rb +1 -1
- data/app/models/jumbotron/team.rb +11 -0
- data/app/services/jumbotron/services/canonical/upsert_team.rb +16 -0
- data/app/services/jumbotron/services/public/assemble_public_game.rb +5 -1
- data/db/migrate/20260827150001_add_key_to_jumbotron_teams.rb +49 -0
- data/lib/jumbotron/team_key.rb +22 -0
- data/lib/jumbotron/version.rb +1 -1
- data/lib/jumbotron.rb +1 -0
- data/spec/factories/jumbotron/team.rb +6 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 31fa4d11ab93d13b5e6db4ab799f05f69b6153067ceb0894677e07bd785c27a3
|
|
4
|
+
data.tar.gz: 2f660fdbdf85bb67f9212c6c8c55b6bc9f49a2699c643070a5496946d8894259
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ee10748cd68f85baa4c3774ef6f7fbcd4c6376f76927a442a8e4ce1b4e28e34c56f7c6355af29545ba1306f7367e37499a56dbdb00f990e413aea020cf37079e
|
|
7
|
+
data.tar.gz: 30e89a701a8dc935ac6d0d4aeffc61d982b6a800d97f86ac43035a23d4ac480bd60485c6c8e96093eaef022b128693ccf0b663b63716dab53385bce0e79ea174
|
|
@@ -19,7 +19,7 @@ module Jumbotron
|
|
|
19
19
|
:season_phase,
|
|
20
20
|
:kind
|
|
21
21
|
)
|
|
22
|
-
Team = Data.define(:id, :name)
|
|
22
|
+
Team = Data.define(:id, :name, :key)
|
|
23
23
|
Venue = Data.define(:id, :name)
|
|
24
24
|
Participant = Data.define(:role, :score, :result, :team)
|
|
25
25
|
GameSegment = Data.define(:kind, :number)
|
|
@@ -7,5 +7,16 @@ module Jumbotron
|
|
|
7
7
|
has_many :provider_identities, as: :target, inverse_of: :target, dependent: :restrict_with_exception
|
|
8
8
|
|
|
9
9
|
validates :name, presence: true
|
|
10
|
+
validates :key, presence: true, uniqueness: true
|
|
11
|
+
validate :key_format_must_be_semantic
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def key_format_must_be_semantic
|
|
16
|
+
return if key.blank?
|
|
17
|
+
return if Jumbotron::TeamKey.valid_format?(key)
|
|
18
|
+
|
|
19
|
+
errors.add(:key, "must be a lowercase kebab-case semantic key")
|
|
20
|
+
end
|
|
10
21
|
end
|
|
11
22
|
end
|
|
@@ -57,6 +57,7 @@ module Jumbotron
|
|
|
57
57
|
team.name = team_input.name
|
|
58
58
|
team.changed_at = observed_at
|
|
59
59
|
end
|
|
60
|
+
# key is immutable after assignment — never regenerate from name or provider id
|
|
60
61
|
team.observed_at = observed_at
|
|
61
62
|
team.save!
|
|
62
63
|
team
|
|
@@ -65,13 +66,28 @@ module Jumbotron
|
|
|
65
66
|
def create_new!
|
|
66
67
|
team = Team.create!(
|
|
67
68
|
name: team_input.name,
|
|
69
|
+
key: allocate_key!(team_input.name),
|
|
68
70
|
observed_at: observed_at,
|
|
69
71
|
changed_at: observed_at
|
|
70
72
|
)
|
|
71
73
|
change_set.record(subject: team, attribute: "name", previous: nil, new_value: team.name)
|
|
74
|
+
change_set.record(subject: team, attribute: "key", previous: nil, new_value: team.key)
|
|
72
75
|
team
|
|
73
76
|
end
|
|
74
77
|
|
|
78
|
+
def allocate_key!(name)
|
|
79
|
+
base = Jumbotron::TeamKey.normalize(name)
|
|
80
|
+
return base unless Team.exists?(key: base)
|
|
81
|
+
|
|
82
|
+
suffix = 2
|
|
83
|
+
loop do
|
|
84
|
+
candidate = "#{base}-#{suffix}"
|
|
85
|
+
return candidate unless Team.exists?(key: candidate)
|
|
86
|
+
|
|
87
|
+
suffix += 1
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
75
91
|
def recover_after_race!
|
|
76
92
|
ref = team_input.provider_identities.first
|
|
77
93
|
identity = ProviderIdentity.find_by!(
|
|
@@ -69,7 +69,11 @@ module Jumbotron
|
|
|
69
69
|
role: participant.role,
|
|
70
70
|
score: participant.score,
|
|
71
71
|
result: participant.result,
|
|
72
|
-
team: Jumbotron::Public::Team.new(
|
|
72
|
+
team: Jumbotron::Public::Team.new(
|
|
73
|
+
id: participant.team.id,
|
|
74
|
+
name: participant.team.name,
|
|
75
|
+
key: participant.team.key
|
|
76
|
+
)
|
|
73
77
|
)
|
|
74
78
|
end
|
|
75
79
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class AddKeyToJumbotronTeams < ActiveRecord::Migration[8.1]
|
|
4
|
+
def up
|
|
5
|
+
add_column :jumbotron_teams, :key, :string, limit: 191
|
|
6
|
+
backfill_keys!
|
|
7
|
+
change_column_null :jumbotron_teams, :key, false
|
|
8
|
+
add_index :jumbotron_teams, :key, unique: true, name: "index_jumbotron_teams_on_key"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def down
|
|
12
|
+
remove_index :jumbotron_teams, name: "index_jumbotron_teams_on_key"
|
|
13
|
+
remove_column :jumbotron_teams, :key
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def backfill_keys!
|
|
19
|
+
say_with_time "backfill jumbotron_teams.key" do
|
|
20
|
+
taken = {}
|
|
21
|
+
connection.select_all("SELECT id, name FROM jumbotron_teams ORDER BY id").each do |row|
|
|
22
|
+
key = allocate_key(normalize_name(row["name"]), taken)
|
|
23
|
+
taken[key] = true
|
|
24
|
+
connection.execute(
|
|
25
|
+
"UPDATE jumbotron_teams SET `key` = #{connection.quote(key)} WHERE id = #{row['id'].to_i}"
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def normalize_name(name)
|
|
32
|
+
slug = name.to_s.unicode_normalize(:nfc).downcase
|
|
33
|
+
slug = slug.gsub(/[^a-z0-9]+/, "-").gsub(/\A-+|-+\z/, "")
|
|
34
|
+
slug = "team" if slug.blank?
|
|
35
|
+
slug
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def allocate_key(base, taken)
|
|
39
|
+
return base unless taken[base]
|
|
40
|
+
|
|
41
|
+
suffix = 2
|
|
42
|
+
loop do
|
|
43
|
+
candidate = "#{base}-#{suffix}"
|
|
44
|
+
return candidate unless taken[candidate]
|
|
45
|
+
|
|
46
|
+
suffix += 1
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Jumbotron
|
|
4
|
+
# Immutable semantic public team identity helper.
|
|
5
|
+
# Derives a kebab-case slug once at assignment; callers must not re-run on rename.
|
|
6
|
+
module TeamKey
|
|
7
|
+
FORMAT = /\A[a-z0-9]+(?:-[a-z0-9]+)*\z/
|
|
8
|
+
|
|
9
|
+
module_function
|
|
10
|
+
|
|
11
|
+
def normalize(name)
|
|
12
|
+
slug = name.to_s.unicode_normalize(:nfc).downcase
|
|
13
|
+
slug = slug.gsub(/[^a-z0-9]+/, "-").gsub(/\A-+|-+\z/, "")
|
|
14
|
+
slug = "team" if slug.blank?
|
|
15
|
+
slug
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def valid_format?(key)
|
|
19
|
+
key.to_s.match?(FORMAT)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/jumbotron/version.rb
CHANGED
data/lib/jumbotron.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jumbotron
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- matt-taylor
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-08-
|
|
11
|
+
date: 2026-08-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: command_tower
|
|
@@ -205,6 +205,7 @@ files:
|
|
|
205
205
|
- db/migrate/20260813000001_create_jumbotron_schedule_groups.rb
|
|
206
206
|
- db/migrate/20260814000001_create_jumbotron_line_observations.rb
|
|
207
207
|
- db/migrate/20260820000001_add_progress_to_jumbotron_games.rb
|
|
208
|
+
- db/migrate/20260827150001_add_key_to_jumbotron_teams.rb
|
|
208
209
|
- docs/testing.md
|
|
209
210
|
- docs/upgrades/0.1.2.md
|
|
210
211
|
- docs/upgrades/0.1.3.md
|
|
@@ -212,6 +213,7 @@ files:
|
|
|
212
213
|
- lib/jumbotron.rb
|
|
213
214
|
- lib/jumbotron/client.rb
|
|
214
215
|
- lib/jumbotron/engine.rb
|
|
216
|
+
- lib/jumbotron/team_key.rb
|
|
215
217
|
- lib/jumbotron/testing.rb
|
|
216
218
|
- lib/jumbotron/version.rb
|
|
217
219
|
- lib/tasks/jumbotron_schedules.rake
|