Module: Kite::Helpers

Included in:
Configuration, Core, Generate, Module
Defined in:
lib/kite/helpers.rb,
lib/kite/helpers/concourse.rb

Defined Under Namespace

Modules: Concourse

Instance Method Summary collapse

Instance Method Details

#check_cloud_config(config) ⇒ Object

Check config/cloud.yml file to be complete

Raises:



3
4
5
# File 'lib/kite/helpers.rb', line 3

def check_cloud_config(config)
  raise Kite::Error, 'The config/cloud.yml is not filled out!' unless config.find { |key, hash| hash.find { |k, v| v.nil? } }.nil?
end

#cloud_pathObject



14
15
16
17
18
19
20
21
# File 'lib/kite/helpers.rb', line 14

def cloud_path
  Dir.pwd.tap do |path|
    until cloud_valid? path
      raise Kite::Error, "Invalid path: \"#{Dir.pwd}\"" if path == "/"
      path = File.dirname(path)
    end
  end
end

#cloud_valid?(path) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
# File 'lib/kite/helpers.rb', line 7

def cloud_valid?(path)
  valid = Dir.children(path).include? 'config'
  valid &&= Dir.children(path + '/config').include? 'cloud.yml'

  valid
end

#parse_cloud_config(env = nil) ⇒ Object

Parse config/cloud.yml, returning the output hash



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kite/helpers.rb', line 24

def parse_cloud_config(env = nil)
  cloud_config = YAML.load(File.read('config/cloud.yml'))
  check_cloud_config(cloud_config)

  if env
    unless cloud_config[env]
      fail "Environement `#{env}` missing in config/cloud.yml"
    end
    return cloud_config[env]
  end
  return cloud_config
end

#run!(command, config = {}) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/kite/helpers.rb', line 37

def run!(command, config = {})
  run(command)

  if $?.exitstatus != 0
    raise Thor::Error.new("command failed: #{ command }")
  end
end