Class: EY::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ey_config.rb,
lib/ey_config/local.rb,
lib/ey_config/version.rb

Defined Under Namespace

Classes: Local

Constant Summary collapse

DEPLOYED_CONFIG_PATH =
'config/ey_services_config_deploy.yml'
PATHS_TO_CHECK =
[DEPLOYED_CONFIG_PATH, EY::Config::Local.config_path]
VERSION =
"0.0.6"

Class Method Summary collapse

Class Method Details

.config_path=(val) ⇒ Object



9
10
11
12
# File 'lib/ey_config.rb', line 9

def config_path=(val)
  @full_path = nil
  @config_paths = [val]
end

.config_pathsObject



14
15
16
# File 'lib/ey_config.rb', line 14

def config_paths
  @config_paths ||= PATHS_TO_CHECK
end

.full_pathObject



18
19
20
# File 'lib/ey_config.rb', line 18

def full_path
  @full_path ||= find_config(config_paths)
end

.get(*args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ey_config.rb', line 40

def get(*args)
  @args = args
  init unless @config
  hash = @config.dup
  args.each do |arg|
    hash = hash[arg.to_s] if hash
  end
  if hash.nil?
    err_message = "No config found for #{args.inspect}. "
    if detected_a_dev_environment?
      err_message += "You can put development/fallback configs in: #{EY::Config::Local.config_path}"
    else
      err_message += "Activate the services that provides '#{args.first}' or remove the code that uses it."
    end
    warn err_message
    raise ArgumentError, err_message
  end
  hash.freeze
end

.initObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ey_config.rb', line 22

def init
  unless File.exists?(full_path)
    err_msg = ""
    if detected_a_dev_environment?
      ey_config_local_usage
      err_msg = "Expected to find EY::Config YAML file at: #{EY::Config::Local.config_path}"
    else
      err_msg = "Expected to find EY::Config YAML file at: #{DEPLOYED_CONFIG_PATH}"
    end
    warn err_msg
    raise ArgumentError, err_msg
  end
  @config = YAML.load_file(full_path)
  unless valid_structure?(@config)
    ey_config_empty_warning(full_path, @config)
  end
end