Sha256: ecb888696d7d7d039b8634c67859cb6ff9ac29ad18c75913ffe035511f357382

Contents?: true

Size: 1.36 KB

Versions: 52

Compression:

Stored size: 1.36 KB

Contents

# encoding: utf-8
module Mongoid
  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 raises an error.
      #
      # @example Get the env name.
      #   Environment.env_name
      #
      # @raise [ Errors::NoEnvironment ] If no environment was set.
      #
      # @return [ String ] The name of the current environment.
      #
      # @since 2.3.0
      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(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, environment = nil)
        env = environment ? environment.to_s : env_name
        YAML.load(ERB.new(File.new(path).read).result)[env]
      end
    end
  end
end

Version data entries

52 entries across 48 versions & 3 rubygems

Version Path
mongoid-6.4.8 lib/mongoid/config/environment.rb
mongoid-6.4.7 lib/mongoid/config/environment.rb
mongoid-6.4.5 lib/mongoid/config/environment.rb
mongoid-5.4.1 lib/mongoid/config/environment.rb
mongoid-7.0.5 lib/mongoid/config/environment.rb
mongoid-7.0.4 lib/mongoid/config/environment.rb
mongoid-6.4.4 lib/mongoid/config/environment.rb
mongoid-7.0.3 lib/mongoid/config/environment.rb
mongoid-6.4.2 lib/mongoid/config/environment.rb
mongoid-7.0.2 lib/mongoid/config/environment.rb
mongoid-7.0.1 lib/mongoid/config/environment.rb
mongoid-6.4.1 lib/mongoid/config/environment.rb
mongoid-5.4.0 lib/mongoid/config/environment.rb
tdiary-5.0.8 vendor/bundle/gems/mongoid-6.4.0/lib/mongoid/config/environment.rb
mongoid-7.0.0 lib/mongoid/config/environment.rb
mongoid-6.4.0 lib/mongoid/config/environment.rb
mongoid-6.3.0 lib/mongoid/config/environment.rb
mongoid-6.2.1 lib/mongoid/config/environment.rb
mongoid-7.0.0.beta lib/mongoid/config/environment.rb
tdiary-5.0.5 vendor/bundle/gems/mongoid-6.1.0/lib/mongoid/config/environment.rb