Module: RailsEnvLocal
- Defined in:
- lib/rails_env_local.rb,
lib/rails_env_local/version.rb,
lib/rails_env_local/rails_env.rb
Overview
Usage:
In config/boot.rb you have:
require 'bundler/setup'
After that line (or before, see NOTE below) add:
require 'rails_env_local'
RailsEnvLocal.set_local_environment
NOTE: If you need your custom local environment to be set before some of the other gems you use,
because they rely on the environment being set early,
then just place the two lines above *before* the `require 'bundler/setup'`. Simple as that.
Options:
environment: a string (default is "localdev")
Effect: will set the Rails environment (Rails.env) to the given string
Example: RailsEnvLocal.set_local_environment(environment: "panda")
verbose: true or false (default is false)
Effect: will print the environment to STDOUT as it is being set
Example: RailsEnvLocal.set_local_environment(verbose: true)
set_rack_env: true or false (default is true)
Effect: will additionally set RAILS_ENV to match Rails.env
Example: RailsEnvLocal.set_local_environment(set_rack_env: false)
set_rails_env: true or false (default is true)
Effect: will additionally set RACK_ENV to match Rails.env
Example: RailsEnvLocal.set_local_environment(set_rails_env: false)
force: true or false (default is false)
Effect: will set Rails.env to environment no matter what.
Example: RailsEnvLocal.set_local_environment(force: true)
Defined Under Namespace
Modules: RailsEnv
Constant Summary collapse
- ORIGINAL_RAILS_DEVELOPMENT_ENVIRONMENT =
"development"
- ALTERNATE_RAILS_DEVELOPMENT_ENVIRONMENT =
Q: Why not just “local”? A: It is too generic. “local” is often used in the same ordinal position as, but with a different meaning than,
the environment name. For one example of this see: https://github.com/bkeepers/dotenv#multiple-rails-environments
"localdev"
- VERSION =
"0.3.0"
Class Method Summary collapse
Class Method Details
.set_local_environment(environment: ALTERNATE_RAILS_DEVELOPMENT_ENVIRONMENT, **options) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rails_env_local.rb', line 48 def self.set_local_environment(environment: ALTERNATE_RAILS_DEVELOPMENT_ENVIRONMENT, **) = {set_rails_env: true, set_rack_env: true, verbose: false, force: false}.merge() if was_development? || was_default? || [:force] Rails.env = environment ENV["RAILS_ENV"] = Rails.env if [:set_rails_env] ENV["RACK_ENV"] = Rails.env if [:set_rack_env] puts "switching to custom local development environment: #{environment}" if [:verbose] elsif [ENV["RAILS_ENV"], ENV["RACK_ENV"], Rails.env].compact.uniq.length > 1 msg = %(ENV["RAILS_ENV"], ENV["RACK_ENV"] and Rails.env are out of sync) if [:verbose] warn(msg) Rails.logger.error(msg) if Rails.logger end end |