Sha256: 6d07928d8bfb2a8704a71a829581372935cb8d10966e1b18d3f0dcc7b877f1f0

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

Stored size: 1.09 KB

Contents

require "teabag/exceptions"

module Teabag
  module Environment

    def self.load(options = {})
      unless rails_loaded?
        require_environment(options[:environment])
        raise "Rails environment not found." unless rails_loaded?
      end

      require "teabag"

      configure_from_options(options)
    end

    def self.require_environment(override = nil)
      return require_env(File.expand_path(override, Dir.pwd)) if override

      standard_environments.each do |filename|
        file = File.expand_path(filename, Dir.pwd)
        return require_env(file) if File.exists?(file)
      end

      raise Teabag::EnvironmentNotFound
    end

    def self.standard_environments
      ["spec/teabag_env.rb", "test/teabag_env.rb", "teabag_env.rb"]
    end

    def self.configure_from_options(options)
      options.each do |key, value|
        Teabag.configuration.send("#{key.downcase}=", value) if Teabag.configuration.respond_to?("#{key.downcase}=")
      end
    end

    def self.require_env(file)
      require(file)
    end

    def self.rails_loaded?
      defined?(Rails)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
teabag-0.5.3 lib/teabag/environment.rb
teabag-0.5.2 lib/teabag/environment.rb
teabag-0.5.1 lib/teabag/environment.rb
teabag-0.5.0 lib/teabag/environment.rb