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

Instance Method Summary collapse

Instance Attribute Details

#config_pathObject



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

#environmentObject

Returns the value of attribute environment.



20
21
22
# File 'lib/modesty/load.rb', line 20

def environment
  @environment
end

#experiments_dirObject



4
5
6
# File 'lib/modesty/load/load_experiments.rb', line 4

def experiments_dir
  @experiments_dir ||= File.join(Modesty.root, 'experiments')
end

#metrics_dirObject



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

#rootObject



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)
  options = load_options(true)
  load_paths(options)
  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!
  options = load_options
  load_paths(options)

  if options['datastore'] && options['datastore']['type']
    type = options['datastore'].delete('type')
    data_options = Hash[
      options['datastore'].map { |k,v| [k.to_sym, v] }
    ]
    self.set_store(type, data_options)
  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 load_options(quiet = false)
  options = begin
    YAML.load(File.read(self.config_path))
  rescue Errno::ENOENT
    puts "No Modesty config file found" unless quiet
    {}
  end
  options[self.environment] || options['default'] || options
end

#load_paths(options) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/modesty/load.rb', line 32

def load_paths(options)
  if options['paths']
    options['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