Class: Moto::Config::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/config/manager.rb

Class Method Summary collapse

Class Method Details

.config_environmentMoto::Config::Hash

Returns Configuration for selected environment + current thread combination.

Returns:

  • (Moto::Config::Hash)

    Configuration for selected environment + current thread combination



67
68
69
# File 'lib/config/manager.rb', line 67

def self.config_environment
  Thread.current['config_environment'] ||= Moto::Config::Hash.new.merge!(Marshal.load(Marshal.dump(@@env_consts)))
end

.config_motoHash

Returns Hash representing data from MotoApp/config/moto.rb file.

Returns:

  • (Hash)

    Hash representing data from MotoApp/config/moto.rb file



61
62
63
# File 'lib/config/manager.rb', line 61

def self.config_moto
  @@moto
end

.environmentString

Returns String representing the name of the current environment.

Returns:

  • (String)

    String representing the name of the current environment



9
10
11
# File 'lib/config/manager.rb', line 9

def self.environment
  @@environment
end

.environment=(environment) ⇒ Object

Parameters:

  • environment (String)

    Sets a string that will represent environment in configuration, on which various settings will depend, for example env. constants



15
16
17
# File 'lib/config/manager.rb', line 15

def self.environment=(environment)
  @@environment = environment
end

.load_configuration(config_name, env) ⇒ Object

Loads configuration for whole test run and files responsible for environmental constants.

Parameters:

  • config_name (String)

    Name of the main Moto/MotoApp config to be loaded. Without extension.

  • env (String)

    Name of the env config to be loaded in addition to /config/environments/common. Without extension.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/config/manager.rb', line 22

def self.load_configuration(config_name, env)

  if config_name
    config_path = "#{MotoApp::DIR}/config/#{config_name}.rb"
  else
    config_path = "#{MotoApp::DIR}/config/moto.rb"
  end

  if File.exists?(config_path)
    @@moto = eval(File.read(config_path))

    # Try reading constants that are common for all environments
    begin
      common_constants = eval(File.read('config/environments/common.rb'))
    rescue
      common_constants = {}
    end

    # Try reading constants specific to current environment
    if env
      self.environment = env

      begin
        environment_constants = eval(File.read("config/environments/#{@@environment}.rb"))
      rescue
        environment_constants = {}
      end
    end

    if environment_constants
      @@env_consts = common_constants.deep_merge(environment_constants)
    end

  else
    raise "Config file: #{config_path} does not exist.\nDoes current working directory contain Moto application?"
  end
end