@@ -16,8 +16,13 @@ defmodule GameServer.Settings.Provider do
1616 The declaration is the only place a setting is written down. Its environment
1717 variable name is **derived** — `<ROOT>_<GROUP>_<KEY>`, e.g.
1818 `GAMEND_RETENTION_CHAT_MESSAGES_DAYS` — so the key and its env var can never
19- disagree. Pass `env:` only for the handful of names other software owns
20- (`PORT`, `DATABASE_URL`), which should also carry `external: true`.
19+ disagree. There is no way to pin a different name: every setting follows the
20+ convention, without exception.
21+
22+ A variable that *other* software reads (`RELEASE_COOKIE` for the release boot
23+ script, `FLY_REGION` from the platform) is not a setting and does not belong
24+ here — renaming our declaration would not rename what that software reads.
25+ Report those separately; `GameServer.Cluster.environment/0` is the example.
2126
2227 Values are read back with `GameServer.Settings.get/2`, which checks
2328 `Application.get_env(app, module)` and falls back to the compiled default. A
@@ -33,10 +38,6 @@ defmodule GameServer.Settings.Provider do
3338 - `:root` — first segment of the env name. Defaults to `"GAMEND"`; a plugin
3439 passes its own (`root: "POLYGLOT"`).
3540 - `:label` — display name for the group. Defaults to a capitalised `:group`.
36- - `:env_prefix` — replaces the derived `<ROOT>_<GROUP>_` prefix for every
37- setting in the provider, so `LIMIT_MAX_PAGE_SIZE` can keep its name while
38- the group is `:limits`. A transitional escape hatch for names that predate
39- the convention; a per-setting `env:` still wins over it.
4041
4142 ## Options for `setting/3`
4243
@@ -50,22 +51,18 @@ defmodule GameServer.Settings.Provider do
5051 them to hold.
5152 - `:with` — sibling keys forming a complete-or-empty group. All unset is
5253 silent; a partial set trips `:required`.
53- - `:env` — override the derived env var name. For inherited names only.
54- - `:external` — this name belongs to other software; the viewer files it
55- under "Inherited" rather than implying we own it.
5654 """
5755
5856 @ types [ :string , :integer , :float , :boolean , :atom , :list , :log_level ]
5957
60- @ setting_opts [ :default , :doc , :secret , :required , :when , :with , :env , :external ]
58+ @ setting_opts [ :default , :doc , :secret , :required , :when , :with ]
6159
6260 @ doc false
6361 defmacro __using__ ( opts ) do
6462 app = Keyword . fetch! ( opts , :app )
6563 group = Keyword . fetch! ( opts , :group )
6664 root = Keyword . get ( opts , :root , "GAMEND" )
6765 label = Keyword . get ( opts , :label ) || group |> to_string ( ) |> String . capitalize ( )
68- env_prefix = Keyword . get ( opts , :env_prefix )
6966
7067 quote do
7168 import GameServer.Settings.Provider , only: [ setting: 2 , setting: 3 ]
@@ -76,7 +73,6 @@ defmodule GameServer.Settings.Provider do
7673 @ gamend_settings_group unquote ( group )
7774 @ gamend_settings_root unquote ( root )
7875 @ gamend_settings_label unquote ( label )
79- @ gamend_settings_env_prefix unquote ( env_prefix )
8076
8177 @ before_compile GameServer.Settings.Provider
8278 end
@@ -98,16 +94,8 @@ defmodule GameServer.Settings.Provider do
9894 group = Module . get_attribute ( module , :gamend_settings_group )
9995 root = Module . get_attribute ( module , :gamend_settings_root )
10096 label = Module . get_attribute ( module , :gamend_settings_label )
101- env_prefix = Module . get_attribute ( module , :gamend_settings_env_prefix )
10297
103- context = % {
104- module: module ,
105- app: app ,
106- group: group ,
107- root: root ,
108- label: label ,
109- env_prefix: env_prefix
110- }
98+ context = % { module: module , app: app , group: group , root: root , label: label }
11199
112100 definitions =
113101 module
@@ -155,10 +143,9 @@ option(s) #{inspect(unknown)}; expected one of #{inspect(@setting_opts)}"
155143 label: label ,
156144 type: type ,
157145 default: Keyword . get ( opts , :default ) ,
158- env: Keyword . get ( opts , :env ) || derive_env ( root , group , key , context . env_prefix ) ,
146+ env: derive_env ( root , group , key ) ,
159147 doc: Keyword . get ( opts , :doc , "" ) ,
160148 secret: Keyword . get ( opts , :secret , false ) ,
161- external: Keyword . get ( opts , :external , false ) ,
162149 required: required ,
163150 when: Keyword . get ( opts , :when ) ,
164151 with: Keyword . get ( opts , :with , [ ] )
@@ -168,16 +155,10 @@ option(s) #{inspect(unknown)}; expected one of #{inspect(@setting_opts)}"
168155 @ doc """
169156 The environment variable name for a group and key: `<ROOT>_<GROUP>_<KEY>`.
170157
171- A provider-level `env_prefix` replaces the `<ROOT>_<GROUP>_` part .
158+ The only way a setting gets a name. There is no override .
172159 """
173- @ spec derive_env ( String . t ( ) , atom ( ) , atom ( ) , String . t ( ) | nil ) :: String . t ( )
174- def derive_env ( root , group , key , env_prefix \\ nil )
175-
176- def derive_env ( _root , _group , key , env_prefix ) when is_binary ( env_prefix ) do
177- env_prefix <> String . upcase ( to_string ( key ) )
178- end
179-
180- def derive_env ( root , group , key , nil ) do
160+ @ spec derive_env ( String . t ( ) , atom ( ) , atom ( ) ) :: String . t ( )
161+ def derive_env ( root , group , key ) do
181162 [ root , to_string ( group ) , to_string ( key ) ]
182163 |> Enum . map_join ( "_" , & String . upcase / 1 )
183164 end
0 commit comments