Module: MongoRequestLogger::MongoidConfig::Environment
- Extended by:
- Environment
- Included in:
- Environment
- Defined in:
- lib/mongo_request_logger/mongoid_config.rb
Overview
Encapsulates logic for getting environment information.
Instance Method Summary collapse
-
#env_name ⇒ String
Get the name of the environment that we are running under.
-
#load_yaml(path, environment = nil) ⇒ Hash
Load the yaml from the provided path and return the settings for the current environment.
Instance Method Details
#env_name ⇒ String
Get the name of the environment that we are running under. This first looks for Rails, then Sinatra, then a RACK_ENV environment variable, and if none of those are found raises an error.
72 73 74 75 76 |
# File 'lib/mongo_request_logger/mongoid_config.rb', line 72 def env_name return Rails.env if defined?(Rails) && Rails.respond_to?(:env) return Sinatra::Base.environment.to_s if defined?(Sinatra) ENV["RACK_ENV"] || ENV["MONGOID_ENV"] || raise(NoEnvironment.new) end |
#load_yaml(path, environment = nil) ⇒ Hash
Load the yaml from the provided path and return the settings for the current environment.
89 90 91 92 |
# File 'lib/mongo_request_logger/mongoid_config.rb', line 89 def load_yaml(path, environment = nil) env = environment ? environment.to_s : env_name YAML.load(ERB.new(File.new(path).read).result)[env] end |