Module: Mongoid::Config::Environment
Overview
Encapsulates logic for getting environment information.
Instance Method Summary collapse
-
#env_name ⇒ String
Get the name of the environment that Mongoid is running under.
-
#load_yaml(path, environment = nil) ⇒ Hash
private
Load the yaml from the provided path and return the settings for the specified environment, or for the current Mongoid environment.
Instance Method Details
#env_name ⇒ String
Get the name of the environment that Mongoid is running under.
Uses the following sources in order:
-
If
::Rails
is defined,Rails.env
. -
If
::Sinatra
is defined,Sinatra::Base.environment
. -
RACK_ENV
-
+MONGOID_ENV*
29 30 31 32 33 34 35 36 37 |
# File 'lib/mongoid/config/environment.rb', line 29 def env_name if defined?(::Rails) return ::Rails.env end if defined?(::Sinatra) return ::Sinatra::Base.environment.to_s end ENV["RACK_ENV"] || ENV["MONGOID_ENV"] or raise Errors::NoEnvironment end |
#load_yaml(path, environment = nil) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Load the yaml from the provided path and return the settings for the specified environment, or for the current Mongoid environment.
53 54 55 56 |
# File 'lib/mongoid/config/environment.rb', line 53 def load_yaml(path, environment = nil) env = environment ? environment.to_s : env_name YAML.load(ERB.new(File.new(path).read).result)[env] end |