Class: Metrician::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/metrician/configuration.rb

Constant Summary collapse

FileMissing =
Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.app_locationsObject



30
31
32
33
34
35
# File 'lib/metrician/configuration.rb', line 30

def self.app_locations
  [
    File.join(Dir.pwd, "config", "metrician.yaml"),
    File.join(Dir.pwd, "config", "metrician.yml"),
  ]
end

.config_locationsObject



17
18
19
# File 'lib/metrician/configuration.rb', line 17

def self.config_locations
  [env_location, *app_locations, gem_location].compact
end

.env_locationObject



21
22
23
24
25
26
27
28
# File 'lib/metrician/configuration.rb', line 21

def self.env_location
  path = ENV["METRICIAN_CONFIG"]
  if path && !File.exist?(path)
    # this should never raise unless a bad ENV setting has been set
    raise(FileMissing.new(path))
  end
  path
end

.gem_locationObject



37
38
39
# File 'lib/metrician/configuration.rb', line 37

def self.gem_location
  File.expand_path("../../../metrician.defaults.yaml", __FILE__)
end

.loadObject



7
8
9
10
11
12
13
14
15
# File 'lib/metrician/configuration.rb', line 7

def self.load
  reset_dependents

  config = {}
  config_locations.reverse.each do |location|
    config.deep_merge!(YAML.load_file(location)) if File.exist?(location)
  end
  config
end

.reset_dependentsObject



41
42
43
44
# File 'lib/metrician/configuration.rb', line 41

def self.reset_dependents
  Metrician::Jobs.reset
  Metrician::Middleware.reset
end