Class: Audioproxy::Rails::Railtie
- Inherits:
-
Rails::Railtie
- Object
- Rails::Railtie
- Audioproxy::Rails::Railtie
- Defined in:
- lib/audioproxy/rails/railtie.rb
Overview
Wires an app's configuration and view helpers. Not an engine: there are no routes, views or migrations to mount.
Constant Summary collapse
- ENV_VARIABLES =
Attribute -> environment variable. The names are the proxy's own, so a dev docker-compose can feed the app and the proxy from one env file (D2). AP_ALLOW_INSECURE maps to
unsigned, which is only the client's flag — the proxy enforces its own independently. { endpoint: "AP_ENDPOINT", key: "AP_KEY", salt: "AP_SALT", unsigned: "AP_ALLOW_INSECURE" }.freeze
- TRUE_VALUES =
The literals Go's strconv.ParseBool accepts, which is what the proxy parses AP_ALLOW_INSECURE with. Deliberately not ActiveModel's boolean cast: that reads every unrecognized string as true, so a stray AP_ALLOW_INSECURE=flase would quietly ship unsigned URLs.
%w[1 t true].freeze
- FALSE_VALUES =
%w[0 f false].freeze
Class Method Summary collapse
-
.apply_configuration(config, credentials:, env:) ⇒ Object
Sources each attribute independently: credentials first, ENV where credentials are silent, nothing at all where both are.
Class Method Details
.apply_configuration(config, credentials:, env:) ⇒ Object
Sources each attribute independently: credentials first, ENV where
credentials are silent, nothing at all where both are. Absent
configuration is not an error here — a signed url_for later raises
the core's ConfigurationError, while an app running unsigned in
development never needs a key (D3). Validating at boot would break
assets:precompile and friends in apps that never generate a URL.
Runs in a railtie initializer, so an app's own
config/initializers/*.rb gets the last word for free.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/audioproxy/rails/railtie.rb', line 68 def apply_configuration(config, credentials:, env:) credentials = normalize_credentials(credentials) ENV_VARIABLES.each do |attribute, variable| value = credentials[attribute] source = :credentials if value.nil? # Blank is absent: an env file that carries AP_KEY= with nothing # after it should fall through, not hand Config an empty string. value = env[variable].presence source = variable end next if value.nil? value = coerce_boolean(value, attribute, source) if attribute == :unsigned config.public_send(:"#{attribute}=", value) end config end |