Module: Modesty::LoadMethods
- Included in:
- API
- Defined in:
- lib/modesty/load.rb,
lib/modesty/load/load_metrics.rb,
lib/modesty/load/load_experiments.rb
Instance Attribute Summary collapse
- #config_path ⇒ Object
-
#environment ⇒ Object
Returns the value of attribute environment.
- #experiments_dir ⇒ Object
- #metrics_dir ⇒ Object
- #root ⇒ Object
Instance Method Summary collapse
- #_load_with_redis(redis) ⇒ Object
- #load! ⇒ Object
- #load_all_experiments! ⇒ Object
- #load_all_metrics! ⇒ Object
- #load_config! ⇒ Object
- #load_options(quiet = false) ⇒ Object
- #load_paths(options) ⇒ Object
- #load_with_redis!(redis) ⇒ Object
Instance Attribute Details
#config_path ⇒ Object
13 14 15 16 17 18 |
# File 'lib/modesty/load.rb', line 13 def config_path @config_path ||= File.join( Modesty.root, '../config/modesty.yml' ) end |
#environment ⇒ Object
Returns the value of attribute environment.
20 21 22 |
# File 'lib/modesty/load.rb', line 20 def environment @environment end |
#experiments_dir ⇒ Object
4 5 6 |
# File 'lib/modesty/load/load_experiments.rb', line 4 def experiments_dir @experiments_dir ||= File.join(Modesty.root, 'experiments') end |
#metrics_dir ⇒ Object
4 5 6 7 8 9 |
# File 'lib/modesty/load/load_metrics.rb', line 4 def metrics_dir @metrics_dir ||= File.join( Modesty.root, 'metrics' ) end |
#root ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/modesty/load.rb', line 4 def root @root ||= File.join( File.dirname(__FILE__), '..' ) #TODO: is there a better default? end |
Instance Method Details
#_load_with_redis(redis) ⇒ Object
55 56 57 58 59 |
# File 'lib/modesty/load.rb', line 55 def _load_with_redis(redis) = (true) load_paths() self.set_store(:redis, :redis => redis) end |
#load! ⇒ Object
61 62 63 64 65 |
# File 'lib/modesty/load.rb', line 61 def load! load_config! load_all_metrics! load_all_experiments! end |
#load_all_experiments! ⇒ Object
8 9 10 11 12 |
# File 'lib/modesty/load/load_experiments.rb', line 8 def load_all_experiments! Dir.glob( File.join(self.experiments_dir, '*.rb') ).each { |f| load f } end |
#load_all_metrics! ⇒ Object
11 12 13 14 15 |
# File 'lib/modesty/load/load_metrics.rb', line 11 def load_all_metrics! Dir.glob( File.join(self.metrics_dir, '**', '*.rb') ).each { |f| load f } end |
#load_config! ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/modesty/load.rb', line 40 def load_config! = load_paths() if ['datastore'] && ['datastore']['type'] type = ['datastore'].delete('type') = Hash[ ['datastore'].map { |k,v| [k.to_sym, v] } ] self.set_store(type, ) else self.set_store :redis, :mock => true end end |
#load_options(quiet = false) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/modesty/load.rb', line 22 def (quiet = false) = begin YAML.load(File.read(self.config_path)) rescue Errno::ENOENT puts "No Modesty config file found" unless quiet {} end [self.environment] || ['default'] || end |
#load_paths(options) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/modesty/load.rb', line 32 def load_paths() if ['paths'] ['paths'].each do |data, path| Modesty.send("#{data}_dir=", File.join(Modesty.root, path)) end end end |
#load_with_redis!(redis) ⇒ Object
67 68 69 70 71 |
# File 'lib/modesty/load.rb', line 67 def load_with_redis!(redis) _load_with_redis(redis) load_all_metrics! load_all_experiments! end |