Class: RippleNetworks::WarningShot::ConfigParser

Inherits:
Object
  • Object
show all
Includes:
RippleNetworks::WarningShot
Defined in:
lib/warning_shot/config_parser.rb

Class Method Summary collapse

Class Method Details

.run(ws) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/warning_shot/config_parser.rb', line 7

def ConfigParser.run(ws)

  env_interned = ws.options[:environment].intern
  configs_not_found = 0

  DepChecker::DEP_FILES.each do |config_file|

    file_path = File.join(ws.options[:configs],%{#{config_file}.yml})

    begin
      yaml = YAML::load(File.open(file_path,"r"))

      #Default missing environments to []
      global = (yaml[:global].nil? || yaml[:global] === true)? [] : yaml[:global]
      running_env = (yaml[env_interned].nil? || yaml[env_interned] === true)? [] : yaml[env_interned]

      #Merge :global and current mode, make unique
      ws.configs[config_file] = global.concat(running_env)
      ws.configs[config_file].uniq!

      ws.record("LOADED: #{config_file}.yml")
    rescue Errno::ENOENT => e
      ws.configs[config_file] = {}
      configs_not_found += 1
      ws.record("NOT FOUND: #{config_file}.yml",:warning)
    rescue Exception => e
      ws.record(e.inspect)
      ws.configs[config_file] = {} 
      ws.record("MALFORMED: #{config_file}.yml",:error)
    end
  end

  if configs_not_found == DepChecker::DEP_FILES.size
    ws.record("No configuration files found!\n\t\tTo generate run 'warning-shot --templates=PATH'",:info)
  end
end