Sha256: ae236f5421571967f500c3a90c70bf1a4c43c0ba07b79ea1ba18ff4c21667793

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 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"] || 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

1 entries across 1 versions & 1 rubygems

Version Path
mongoid-2.4.0 lib/mongoid/config/environment.rb