Class: Experiment::Config
- Inherits:
-
Object
- Object
- Experiment::Config
- Defined in:
- lib/experiment/config.rb
Class Method Summary collapse
- .[](v) ⇒ Object
- .init(env = :development) ⇒ Object
-
.load(experiment, options, env = :development) ⇒ Object
the load method takes the basic config file, which is then overriden by the experimental config file and finally by the options string (which should be in this format: “key: value, key2:value2,key3: value3”).
- .parse(options) ⇒ Object
- .to_h ⇒ Object
Class Method Details
.[](v) ⇒ Object
26 27 28 |
# File 'lib/experiment/config.rb', line 26 def [](v) @config[v.to_s] end |
.init(env = :development) ⇒ Object
21 22 23 24 |
# File 'lib/experiment/config.rb', line 21 def init(env = :development) conf = YAML::load_file("./config/config.yaml") @config = conf["environments"][env.to_s] end |
.load(experiment, options, env = :development) ⇒ Object
the load method takes the basic config file, which is then overriden by the experimental config file and finally by the options string (which should be in this format: “key: value, key2:value2,key3: value3”)
11 12 13 14 15 16 17 18 19 |
# File 'lib/experiment/config.rb', line 11 def load(experiment, , env = :development) init env expath = File.("./experiments/#{experiment}/config.yaml") if File.exists? expath exp = YAML::load_file(expath) @config.merge! exp["experiment"][env.to_s] if exp["experiment"][env.to_s].is_a? Hash end @config.merge! parse() end |
.parse(options) ⇒ Object
30 31 32 |
# File 'lib/experiment/config.rb', line 30 def parse() Hash[.split(/\, ?/).map{|a| a.split /\: ?/ }] end |
.to_h ⇒ Object
34 35 36 |
# File 'lib/experiment/config.rb', line 34 def to_h @config end |