Module: Teabag::Environment

Defined in:
lib/teabag/environment.rb

Class Method Summary collapse

Class Method Details

.configure_from_options(options) ⇒ Object



34
35
36
37
38
# File 'lib/teabag/environment.rb', line 34

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

.load(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/teabag/environment.rb', line 6

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

  require "teabag"
  require "teabag/suite"
  require "teabag/server"

  configure_from_options(options)
end

.rails_loaded?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/teabag/environment.rb', line 44

def self.rails_loaded?
  defined?(Rails)
end

.require_env(file) ⇒ Object



40
41
42
# File 'lib/teabag/environment.rb', line 40

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

.require_environment(override = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/teabag/environment.rb', line 19

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

.standard_environmentsObject



30
31
32
# File 'lib/teabag/environment.rb', line 30

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