Sha256: 697f0c1984570d34fb9c12488fbd6fa2ca3a77bacca61c63acb58ab25458233a

Contents?: true

Size: 1.47 KB

Versions: 4

Compression:

Stored size: 1.47 KB

Contents

module RippleNetworks
  module WarningShot
    class ConfigParser
      require 'yaml'
      include RippleNetworks::WarningShot
      
      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
      
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
warning-shot-0.8.9 lib/warning_shot/config_parser.rb
warning-shot-0.9.1 lib/warning_shot/config_parser.rb
warning-shot-0.9.2 lib/warning_shot/config_parser.rb
warning-shot-0.9.0 lib/warning_shot/config_parser.rb