Class: Moto::Lib::Config
- Inherits:
-
Object
- Object
- Moto::Lib::Config
- Defined in:
- lib/config.rb
Class Method Summary collapse
-
.environment ⇒ String
String representing the name of the current environment.
- .environment=(environment) ⇒ Object
-
.environment_const(key) ⇒ String
Value of the key.
-
.load_configuration(config_name) ⇒ Object
Loads configuration for whole test run and files responsible for environmental constants.
-
.moto ⇒ Hash
Hash representing data from MotoApp/config/moto.rb file.
Class Method Details
.environment ⇒ String
Returns 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
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.
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.
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 |
.moto ⇒ Hash
Returns Hash representing data from MotoApp/config/moto.rb file.
47 48 49 |
# File 'lib/config.rb', line 47 def self.moto @@moto end |