Top Level Namespace

Defined Under Namespace

Modules: CIScripts, Demo, Docker, Git, Ruby

Instance Method Summary collapse

Instance Method Details

#classify(s) ⇒ Object

helpers



71
72
73
74
75
# File 'lib/ci_scripts/helpers.rb', line 71

def classify(s)
  s = s.to_s.split('_').collect(&:capitalize).join
  s[0] = s[0].capitalize
  s
end

#command(*options) ⇒ Object

Timed runs



22
23
24
25
26
27
28
# File 'lib/ci_scripts/helpers.rb', line 22

def command(*options)
  log_info(options.join(" "))
  t = Time.now
  system(*options)
  log_success("#{(Time.now - t).round(2)}s\n ")
  exit $CHILD_STATUS.exitstatus if $CHILD_STATUS && $CHILD_STATUS.exitstatus != 0
end

#env_check(key, value) ⇒ Object

env helpers



48
49
50
51
52
53
# File 'lib/ci_scripts/helpers.rb', line 48

def env_check(key, value)
  unless ENV[key]
    puts "Setting #{key} to #{value}"
    ENV[key] = value
  end
end

#env_fetch(key, default = "") ⇒ Object



62
63
64
65
66
67
68
# File 'lib/ci_scripts/helpers.rb', line 62

def env_fetch(key, default = "")
  if ENV[key]
    ENV[key]
  else
    default
  end
end

#installed?(binary) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/ci_scripts/helpers.rb', line 43

def installed?(binary)
  test_command?("command", "-v", binary)
end

#log_error(s) ⇒ Object



12
13
14
# File 'lib/ci_scripts/helpers.rb', line 12

def log_error(s)
  puts("\x1b[31m#{s}\x1b[0m")
end

#log_info(s) ⇒ Object

Logging



4
5
6
# File 'lib/ci_scripts/helpers.rb', line 4

def log_info(s)
  puts("\x1b[34m#{s}\x1b[0m")
end

#log_success(s) ⇒ Object



8
9
10
# File 'lib/ci_scripts/helpers.rb', line 8

def log_success(s)
  puts("\x1b[32m#{s}\x1b[0m")
end

#nice_exit(code, msg = "Something happened") ⇒ Object



16
17
18
19
# File 'lib/ci_scripts/helpers.rb', line 16

def nice_exit(code, msg="Something happened")
  log_error(msg)
  exit code
end

#required_env(key) ⇒ Object



55
56
57
58
59
60
# File 'lib/ci_scripts/helpers.rb', line 55

def required_env(key)
  unless ENV[key]
    log_error "Required environment variable #{key} not set"
    exit 1
  end
end

#test_command?(*options) ⇒ Boolean

system helpers

Returns:

  • (Boolean)


38
39
40
41
# File 'lib/ci_scripts/helpers.rb', line 38

def test_command?(*options)
  system(*options, out: File::NULL)
  $CHILD_STATUS == 0
end

#timed_run(name) ⇒ Object



30
31
32
33
34
35
# File 'lib/ci_scripts/helpers.rb', line 30

def timed_run(name)
  log_info(name)
  t = Time.now
  yield
  log_success("#{(Time.now - t).round(2)}s\n ")
end

#unindent(s) ⇒ Object



77
78
79
80
# File 'lib/ci_scripts/helpers.rb', line 77

def unindent(s)
  indent = s.split("\n").select { |line| !line.strip.empty? }.map { |line| line.index(/[^\s]/) }.compact.min || 0
  s.gsub(/^[[:blank:]]{#{indent}}/, '')
end