Skip to content

Commit 34775f1

Browse files
Rubocop: Rails/EnvironmentVariableAccess -> config files
1 parent 120f60c commit 34775f1

File tree

15 files changed

+88
-39
lines changed

15 files changed

+88
-39
lines changed

.rubocop.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ Naming/VariableNumber:
2727
AllowedIdentifiers:
2828
- es_419
2929

30-
# TODO: https://docs.rubocop.org/rubocop-rails/cops_rails.html#railsenvironmentvariableaccess
31-
# Consider using `Rails.application.config.foo` instead of `ENV['FOO']`
32-
Rails/EnvironmentVariableAccess:
33-
Enabled: false
34-
3530
RSpec/DescribeClass:
3631
Exclude:
3732
- spec/system/*

app/controllers/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ApplicationController < ActionController::Base
2525
helper :meta
2626

2727
def staging?
28-
ENV.fetch('ON_STAGING') { 'FALSE' } == 'TRUE'
28+
Rails.application.config.x.app.on_staging
2929
end
3030
helper_method :staging?
3131

app/lib/code_archiver.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def run
3434
end
3535

3636
puts '*' * 80
37-
if ENV.fetch('STATIC_EXPORT_IMAGES', nil).present?
37+
if Rails.application.config.x.app.static_export_images
3838
puts 'downloading local copies of article images. this will take a while...'
3939
download_article_images
4040
else

app/lib/feature_flag.rb

Lines changed: 0 additions & 23 deletions
This file was deleted.

app/models/concerns/single_page_tool.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def image side: :front, color: :color
5252
# Rails environment is production in our staging environment for
5353
# heroku reasons. We have environment variables set to distinguish
5454
# between the two.
55-
throw e if Rails.env.production? && ENV.fetch('ON_PRODUCTION') { 'FALSE' } == 'TRUE'
55+
throw e if Rails.env.production? && Rails.application.config.x.app.on_production
5656
''
5757
end
5858

config/application.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,22 @@ class Application < Rails::Application
111111
# is deprecated and will be removed in Rails 8.2
112112
# To opt in to the new behavior, set `config.active_support.to_time_preserves_timezone = :zone`.
113113
config.active_support.to_time_preserves_timezone = :zone
114+
115+
# Load each service specific config file into the application's config,
116+
# using Rails' custom config namespace: x
117+
# Example: Rails.application.config.x.stripe.secret_key
118+
#
119+
# Enumerate through all YAML files in config/services
120+
Rails.root.glob('config/services/*.yml').each do |yaml_filepath|
121+
# Read the service name from the YAML file's name
122+
service_name = File.basename(yaml_filepath, '.yml')
123+
124+
# Read the YAML config file for this service
125+
service_config = config_for("services/#{service_name}")
126+
127+
# Load the service's configuration into the custom config namespace
128+
# Example: when `yaml_filepath` is "stripe.yml", this will call `config.x.stripe =`
129+
config.x.public_send(:"#{service_name}=", service_config)
130+
end
114131
end
115132
end

config/initializers/bugsnag.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Bugsnag.configure do |config|
2-
config.api_key = ENV.fetch('BUGSNAG_API_KEY', nil)
2+
config.api_key = Rails.application.config.x.bugsnag.api_key
33
config.notify_release_stages = %w[staging production]
44

55
# we consider both staging and production as 'production' for heroku
66
# reasons, so set based on ENV variables
77
if Rails.env.production?
8-
staging = ENV.fetch('ON_STAGING') { 'FALSE' } == 'TRUE'
8+
staging = Rails.application.config.x.app.on_staging
99
config.release_stage = staging ? 'staging' : 'production'
1010
else
1111
# otherwise it is 'test' or 'development'

config/initializers/rack_attack.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ class Attack
44
throttle('limit requests per IP', limit: 60, period: 1.minute) do |req|
55
# Allow trusted requests through unthrottled
66
trusted_request =
7-
ENV.fetch('RACK_ATTACK_ALLOWED_USER_AGENT', nil).present? &&
8-
req.user_agent&.starts_with?(ENV.fetch('RACK_ATTACK_ALLOWED_USER_AGENT'))
7+
Rails.application.config.x.rack_attack.allowed_user_agent.present? &&
8+
req.user_agent&.starts_with?(Rails.application.config.x.rack_attack.allowed_user_agent)
99

1010
# Allow Asset Pipeline and ActiveStorage requests through unthrottled
1111
asset_pipeline = req.path.start_with? '/assets'

config/initializers/sidekiq.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SIDEKIQ_REDIS_CONFIGURATION = {
22
# use REDIS_PROVIDER for Redis environment variable name, defaulting to REDIS_URL
3-
url: ENV.fetch(ENV.fetch('REDIS_PROVIDER', 'REDIS_URL'), nil),
3+
url: Rails.application.config.x.redis.url,
44
ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE }
55
}.freeze
66

config/initializers/stripe.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Rails.configuration.stripe = {
2-
publishable_key: ENV.fetch('STRIPE_PUBLISHABLE_KEY', nil),
3-
secret_key: ENV.fetch('STRIPE_SECRET_KEY', nil)
2+
publishable_key: Rails.application.config.x.stripe.publishable_key,
3+
secret_key: Rails.application.config.x.stripe.secret_key
44
}
55

66
Stripe.api_key = Rails.configuration.stripe[:secret_key]
77

8-
STRIPE_MONTHLY_PRICE_ID = ENV.fetch('STRIPE_MONTHLY_PRICE_ID') { 'monthly' }
8+
STRIPE_MONTHLY_PRICE_ID = Rails.application.config.x.stripe.monthly_price_id

0 commit comments

Comments
 (0)