Migrate configuration from direct environment variable access to Rails' config_for mechanism for better organization, testability, and maintainability. Instead of accessing ENV variables directly throughout the codebase, consolidate them into YAML configuration files loaded at application startup.
Migrate configuration from direct environment variable access to Rails’ config_for mechanism for better organization, testability, and maintainability. Instead of accessing ENV variables directly throughout the codebase, consolidate them into YAML configuration files loaded at application startup.
Why this matters:
How to apply:
Example:
# Before - scattered ENV access
def mfa_force_enabled?
ENV['MFA_FORCE'] == 'true'
end
def authorized_fetch_mode?
%w(true all).include?(ENV.fetch('AUTHORIZED_FETCH', 'false'))
end
# After - centralized in config/mastodon.yml
# mfa_force: <%= ENV.fetch('MFA_FORCE', 'false') %>
# authorized_fetch: <%= ENV.fetch('AUTHORIZED_FETCH', 'false') %>
# Then access via:
def mfa_force_enabled?
Rails.configuration.x.mastodon.mfa_force == 'true'
end
def authorized_fetch_mode?
%w(true all).include?(Rails.configuration.x.mastodon.authorized_fetch)
end
This approach consolidates configuration management while preserving the ability to test environment variable behavior and avoiding configuration logic duplication across the application.
Enter the URL of a public GitHub repository