Class: Moto::Lib::Config

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

Class Method Summary collapse

Class Method Details

.environmentString

Returns String representing the name of the current environment.

Returns:

  • (String)

    String representing the name of the current environment



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

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



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

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

.environment_const(key) ⇒ String

Returns Value of the key.

Parameters:

  • key (String)

    Name of the key which’s value is to be retrieved

Returns:

  • (String)

    Value of the key



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/config.rb', line 54

def self.environment_const(key)
  key = key.to_s

  code = if key.include? '.'
           "@@env_consts#{key.split('.').map { |a| "[:#{a}]" }.join('')}"
         else
           "@@env_consts[:#{key}]"
         end

  begin
    value = eval(code)
    raise if value.nil?
  rescue
    raise "There is no const defined for key: #{key}."
  end

  value
end

.load_configuration(config_name) ⇒ 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.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/config.rb', line 20

def self.load_configuration(config_name)
  config_path = "#{MotoApp::DIR}/config/#{config_name}.rb"

  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
    begin
      environment_constants = eval(File.read("config/environments/#{@@environment}.rb"))
    rescue
      environment_constants = {}
    end

    @@env_consts = common_constants.deep_merge(environment_constants)
  else
    raise "Config file: #{config_path} does not exist.\nDoes current working directory contain Moto application?"
  end
end

.motoHash

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

Returns:

  • (Hash)

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



47
48
49
# File 'lib/config.rb', line 47

def self.moto
  @@moto
end