Class: RuboCop::Cop::Ezcater::RailsEnv

Inherits:
RuboCop::Cop show all
Defined in:
lib/rubocop/cop/ezcater/rails_env.rb

Overview

Use the ‘Rails.configuration.x` namespace for configuration backed by environment variables, rather than inspecting `Rails.env` directly.

Centralizing application configuration helps avoid scattering it throughout the codebase, and avoids coarse environment grouping under a single env var. See ezcater.atlassian.net/wiki/x/ZIChNg.

Examples:


# good
enforce_foo! if Rails.configuration.x.foo_enforced

# bad
enforce_foo! if Rails.env.production?

# bad
enforce_foo! if ENV["RAILS_ENV"] == "production"

Constant Summary collapse

MSG =
<<~END_MESSAGE.split("\n").join(" ")
  Use `Rails.configuration.x.<foo>` for env-backed configuration instead of inspecting `Rails.env`, so that
  configuration is more centralized and gives finer control. https://ezcater.atlassian.net/wiki/x/ZIChNg
END_MESSAGE

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



34
35
36
37
38
# File 'lib/rubocop/cop/ezcater/rails_env.rb', line 34

def on_send(node)
  rails_env(node) do
    add_offense(node, location: :expression, message: MSG)
  end
end