Class: Moto::Config::Manager
- Inherits:
-
Object
- Object
- Moto::Config::Manager
- Defined in:
- lib/config/manager.rb
Class Method Summary collapse
-
.config_environment ⇒ Moto::Config::Hash
Configuration for selected environment + current thread combination.
-
.config_moto ⇒ Hash
Hash representing data from MotoApp/config/moto.rb file.
-
.environment ⇒ String
String representing the name of the current environment.
- .environment=(environment) ⇒ Object
-
.load_configuration(config_name, env) ⇒ Object
Loads configuration for whole test run and files responsible for environmental constants.
Class Method Details
.config_environment ⇒ Moto::Config::Hash
Returns 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_moto ⇒ Hash
Returns 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 |
.environment ⇒ String
Returns 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
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.
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 |