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.7"

Class Method Summary collapse

Class Method Details

.configObject



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

def config
  @config || init
end

.config_path=(val) ⇒ Object



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

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

.config_pathsObject



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

def config_paths
  @config_paths ||= PATHS_TO_CHECK
end

.full_pathObject



22
23
24
# File 'lib/ey_config.rb', line 22

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

.get(*args) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ey_config.rb', line 50

def get(*args)
  @args = args
  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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ey_config.rb', line 26

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
  begin
    YAML
  rescue
    require 'yaml'
  end
  @config = YAML.load_file(full_path)
  unless valid_structure?(config)
    ey_config_empty_warning(full_path, config)
  end
  @config
end