Skip to content

Commit 1c08b47

Browse files
committed
fix: adjust Zeitwerk lazy loading in production
- Centralized constants make it easy to add dropdowns in the frontend - Display name mappings available (e.g., Constants::Organization::TIER_NAMES) - No more manual text entry - can use select inputs with predefined options - Consistent validation across the application - Easier to maintain and update
1 parent 95da356 commit 1c08b47

27 files changed

Lines changed: 566 additions & 423 deletions
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
# frozen_string_literal: true
2+
3+
class Api::V1::ConstantsController < ApplicationController
4+
# GET /api/v1/constants
5+
# Public endpoint - no authentication required
6+
def index
7+
render json: {
8+
data: {
9+
regions: regions_data,
10+
organization: organization_data,
11+
user: user_data,
12+
player: player_data,
13+
match: match_data,
14+
scrim: scrim_data,
15+
competitive_match: competitive_match_data,
16+
opponent_team: opponent_team_data,
17+
schedule: schedule_data,
18+
team_goal: team_goal_data,
19+
vod_review: vod_review_data,
20+
vod_timestamp: vod_timestamp_data,
21+
scouting_target: scouting_target_data,
22+
champion_pool: champion_pool_data
23+
}
24+
}
25+
end
26+
27+
private
28+
29+
def regions_data
30+
{
31+
values: Constants::REGIONS,
32+
names: Constants::REGION_NAMES
33+
}
34+
end
35+
36+
def organization_data
37+
{
38+
tiers: {
39+
values: Constants::Organization::TIERS,
40+
names: Constants::Organization::TIER_NAMES
41+
},
42+
subscription_plans: {
43+
values: Constants::Organization::SUBSCRIPTION_PLANS,
44+
names: Constants::Organization::SUBSCRIPTION_PLAN_NAMES
45+
},
46+
subscription_statuses: Constants::Organization::SUBSCRIPTION_STATUSES
47+
}
48+
end
49+
50+
def user_data
51+
{
52+
roles: {
53+
values: Constants::User::ROLES,
54+
names: Constants::User::ROLE_NAMES
55+
}
56+
}
57+
end
58+
59+
def player_data
60+
{
61+
roles: {
62+
values: Constants::Player::ROLES,
63+
names: Constants::Player::ROLE_NAMES
64+
},
65+
statuses: {
66+
values: Constants::Player::STATUSES,
67+
names: Constants::Player::STATUS_NAMES
68+
},
69+
queue_ranks: Constants::Player::QUEUE_RANKS,
70+
queue_tiers: Constants::Player::QUEUE_TIERS
71+
}
72+
end
73+
74+
def match_data
75+
{
76+
types: {
77+
values: Constants::Match::TYPES,
78+
names: Constants::Match::TYPE_NAMES
79+
},
80+
sides: {
81+
values: Constants::Match::SIDES,
82+
names: Constants::Match::SIDE_NAMES
83+
}
84+
}
85+
end
86+
87+
def scrim_data
88+
{
89+
types: {
90+
values: Constants::Scrim::TYPES,
91+
names: Constants::Scrim::TYPE_NAMES
92+
},
93+
focus_areas: {
94+
values: Constants::Scrim::FOCUS_AREAS,
95+
names: Constants::Scrim::FOCUS_AREA_NAMES
96+
},
97+
visibility_levels: {
98+
values: Constants::Scrim::VISIBILITY_LEVELS,
99+
names: Constants::Scrim::VISIBILITY_NAMES
100+
}
101+
}
102+
end
103+
104+
def competitive_match_data
105+
{
106+
formats: {
107+
values: Constants::CompetitiveMatch::FORMATS,
108+
names: Constants::CompetitiveMatch::FORMAT_NAMES
109+
},
110+
sides: {
111+
values: Constants::CompetitiveMatch::SIDES,
112+
names: Constants::Match::SIDE_NAMES
113+
}
114+
}
115+
end
116+
117+
def opponent_team_data
118+
{
119+
tiers: {
120+
values: Constants::OpponentTeam::TIERS,
121+
names: Constants::OpponentTeam::TIER_NAMES
122+
}
123+
}
124+
end
125+
126+
def schedule_data
127+
{
128+
event_types: {
129+
values: Constants::Schedule::EVENT_TYPES,
130+
names: Constants::Schedule::EVENT_TYPE_NAMES
131+
},
132+
statuses: {
133+
values: Constants::Schedule::STATUSES,
134+
names: Constants::Schedule::STATUS_NAMES
135+
}
136+
}
137+
end
138+
139+
def team_goal_data
140+
{
141+
categories: {
142+
values: Constants::TeamGoal::CATEGORIES,
143+
names: Constants::TeamGoal::CATEGORY_NAMES
144+
},
145+
metric_types: {
146+
values: Constants::TeamGoal::METRIC_TYPES,
147+
names: Constants::TeamGoal::METRIC_TYPE_NAMES
148+
},
149+
statuses: {
150+
values: Constants::TeamGoal::STATUSES,
151+
names: Constants::TeamGoal::STATUS_NAMES
152+
}
153+
}
154+
end
155+
156+
def vod_review_data
157+
{
158+
types: {
159+
values: Constants::VodReview::TYPES,
160+
names: Constants::VodReview::TYPE_NAMES
161+
},
162+
statuses: {
163+
values: Constants::VodReview::STATUSES,
164+
names: Constants::VodReview::STATUS_NAMES
165+
}
166+
}
167+
end
168+
169+
def vod_timestamp_data
170+
{
171+
categories: {
172+
values: Constants::VodTimestamp::CATEGORIES,
173+
names: Constants::VodTimestamp::CATEGORY_NAMES
174+
},
175+
importance_levels: {
176+
values: Constants::VodTimestamp::IMPORTANCE_LEVELS,
177+
names: Constants::VodTimestamp::IMPORTANCE_NAMES
178+
},
179+
target_types: {
180+
values: Constants::VodTimestamp::TARGET_TYPES,
181+
names: Constants::VodTimestamp::TARGET_TYPE_NAMES
182+
}
183+
}
184+
end
185+
186+
def scouting_target_data
187+
{
188+
statuses: {
189+
values: Constants::ScoutingTarget::STATUSES,
190+
names: Constants::ScoutingTarget::STATUS_NAMES
191+
},
192+
priorities: {
193+
values: Constants::ScoutingTarget::PRIORITIES,
194+
names: Constants::ScoutingTarget::PRIORITY_NAMES
195+
}
196+
}
197+
end
198+
199+
def champion_pool_data
200+
{
201+
mastery_levels: {
202+
values: Constants::ChampionPool::MASTERY_LEVELS.to_a,
203+
names: Constants::ChampionPool::MASTERY_LEVEL_NAMES
204+
},
205+
priority_levels: Constants::ChampionPool::PRIORITY_LEVELS.to_a
206+
}
207+
end
208+
end

app/models/champion_pool.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
class ChampionPool < ApplicationRecord
2+
# Concerns
3+
include Constants
4+
25
# Associations
36
belongs_to :player
47

58
# Validations
69
validates :champion, presence: true
710
validates :player_id, uniqueness: { scope: :champion }
811
validates :games_played, :games_won, numericality: { greater_than_or_equal_to: 0 }
9-
validates :mastery_level, inclusion: { in: 1..7 }
10-
validates :priority, inclusion: { in: 1..10 }
12+
validates :mastery_level, inclusion: { in: Constants::ChampionPool::MASTERY_LEVELS }
13+
validates :priority, inclusion: { in: Constants::ChampionPool::PRIORITY_LEVELS }
1114

1215
# Scopes
1316
scope :comfort_picks, -> { where(is_comfort_pick: true) }

app/models/competitive_match.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
class CompetitiveMatch < ApplicationRecord
2+
# Concerns
3+
include Constants
4+
25
# Associations
36
belongs_to :organization
47
belongs_to :opponent_team, optional: true
@@ -9,12 +12,12 @@ class CompetitiveMatch < ApplicationRecord
912
validates :external_match_id, uniqueness: true, allow_blank: true
1013

1114
validates :match_format, inclusion: {
12-
in: %w[BO1 BO3 BO5],
15+
in: Constants::CompetitiveMatch::FORMATS,
1316
message: "%{value} is not a valid match format"
1417
}, allow_blank: true
1518

1619
validates :side, inclusion: {
17-
in: %w[blue red],
20+
in: Constants::CompetitiveMatch::SIDES,
1821
message: "%{value} is not a valid side"
1922
}, allow_blank: true
2023

0 commit comments

Comments
 (0)