Sha256: d34c5eff66beade246c6447fb1c9b5d864867f1e7bef27e50a03b312e184147e

Contents?: true

Size: 1.34 KB

Versions: 45

Compression:

Stored size: 1.34 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)
        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

45 entries across 45 versions & 6 rubygems

Version Path
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mongoid-4.0.2/lib/mongoid/config/environment.rb
mongoid-3.1.7 lib/mongoid/config/environment.rb
mongoid-4.0.2 lib/mongoid/config/environment.rb
mongoid-4.0.1 lib/mongoid/config/environment.rb
mongoid-4.0.0 lib/mongoid/config/environment.rb
mongoid-4.0.0.rc2 lib/mongoid/config/environment.rb
mongoid-4.0.0.rc1 lib/mongoid/config/environment.rb
mongoid-4.0.0.beta2 lib/mongoid/config/environment.rb
mongoid-4.0.0.beta1 lib/mongoid/config/environment.rb
mongoid-4.0.0.alpha2 lib/mongoid/config/environment.rb
mongoid-4.0.0.alpha1 lib/mongoid/config/environment.rb
mongoid-3.1.6 lib/mongoid/config/environment.rb
sepastian-mongoid-rails4-4.0.1.alpha lib/mongoid/config/environment.rb
sepastian-mongoid-rails4-4.0.0.alpha lib/mongoid/config/environment.rb
mongoid-3.1.5 lib/mongoid/config/environment.rb
mongoid_heroku_stable-4.0.0 lib/mongoid/config/environment.rb
mongoid_rails4-4.0.0 lib/mongoid/config/environment.rb
mongoid-3.1.4 lib/mongoid/config/environment.rb
mongoid-3.1.3 lib/mongoid/config/environment.rb
mongoid-3.1.2 lib/mongoid/config/environment.rb