Sha256: d5a7cc46f902f6f82908eb97ccffd4ea92d828aaa8db76259e701b94ced900ab
Contents?: true
Size: 1.21 KB
Versions: 153
Compression:
Stored size: 1.21 KB
Contents
# encoding: utf-8 module Mongoid #:nodoc module Config # Encapsulates logic for getting environment information. module Environment extend self # 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 returns "development". # # @example Get the env name. # Environment.env_name # # @return [ String ] The name of the current environment. # # @since 2.3.0 def env_name return Rails.env if defined?(Rails) return Sinatra::Base.environment.to_s if defined?(Sinatra) ENV["RACK_ENV"] || ENV["MONGOID_ENV"] || raise(Errors::NoEnvironment.new) end # Load the yaml from the provided path and return the settings for the # current environment. # # @example Load the yaml. # Environment.load_yaml("/work/mongoid.yml") # # @param [ String ] path The location of the file. # # @return [ Hash ] The settings. # # @since 2.3.0 def load_yaml(path) YAML.load(ERB.new(File.new(path).read).result)[env_name] end end end end
Version data entries
153 entries across 61 versions & 3 rubygems