Module: HerokuFormationValidator

Defined in:
lib/heroku_formation_validator.rb,
lib/heroku_formation_validator/runner.rb,
lib/heroku_formation_validator/version.rb,
lib/heroku_formation_validator/heroku_api.rb,
lib/heroku_formation_validator/plugins/addons.rb,
lib/heroku_formation_validator/plugins/variables.rb,
lib/heroku_formation_validator/plugins/papertrail.rb

Defined Under Namespace

Modules: Plugins Classes: HerokuApi, Runner

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.error(msg) ⇒ Object



47
48
49
# File 'lib/heroku_formation_validator.rb', line 47

def self.error(msg)
  $stderr.puts msg.color(:red)
end

.run(config_file) ⇒ Object



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
43
44
45
# File 'lib/heroku_formation_validator.rb', line 13

def self.run(config_file)
  begin
    cnf = YAML::load(File.open(config_file))
  rescue Errno::ENOENT
    error "File not found: #{config_file}"
    return false
  end
  heroku_api = HerokuApi.new(cnf["auth"]["email"], cnf["auth"]["token"])

  unless heroku_api.ping
    error "Heroku API error. Heroku credential in config is not correct?"
    return false
  end

  success = true
  cnf["groups"].each do |group, validations|
    apps = validations.delete("apps")
    apps.each do |app|
      errors = []
      cnf["common"].merge(validations).each do |plugin, values|
        plugin_klass = "HerokuFormationValidator::Plugins::#{plugin.camelize}".safe_constantize
        errors += plugin_klass.run(heroku_api, app, values).map{|error| "#{plugin.camelize}: #{error}"}
      end

      if errors.length > 0
        success = false
        error "=== #{group} #{app} ==="
        error errors.join("\n")
      end
    end
  end
  success
end