Top Level Namespace
Defined Under Namespace
Modules: CIScripts, Docker, Git, Ruby
Instance Method Summary
collapse
Instance Method Details
#classify(s) ⇒ Object
66
67
68
69
70
|
# File 'lib/ci_scripts/helpers.rb', line 66
def classify(s)
s = s.to_s.split('_').collect(&:capitalize).join
s[0] = s[0].capitalize
s
end
|
#command(*options) ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/ci_scripts/helpers.rb', line 17
def command(*options)
log_info(options.join(" "))
t = Time.now
system(*options)
log_success("#{(Time.now - t).round(2)}s\n ")
exit $CHILD_STATUS if $CHILD_STATUS != 0
end
|
#env_check(key, value) ⇒ Object
43
44
45
46
47
48
|
# File 'lib/ci_scripts/helpers.rb', line 43
def env_check(key, value)
unless ENV[key]
puts "Setting #{key} to #{value}"
ENV[key] = value
end
end
|
#env_fetch(key, default = "") ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/ci_scripts/helpers.rb', line 57
def env_fetch(key, default = "")
if ENV[key]
ENV[key]
else
default
end
end
|
#installed?(binary) ⇒ Boolean
38
39
40
|
# File 'lib/ci_scripts/helpers.rb', line 38
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
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
|
#required_env(key) ⇒ Object
50
51
52
53
54
55
|
# File 'lib/ci_scripts/helpers.rb', line 50
def required_env(key)
unless ENV[key]
log_error "Required environment variable #{key} not set"
exit 1
end
end
|
#test_command?(*options) ⇒ Boolean
33
34
35
36
|
# File 'lib/ci_scripts/helpers.rb', line 33
def test_command?(*options)
system(*options, out: File::NULL)
$CHILD_STATUS == 0
end
|
#timed_run(name) ⇒ Object
25
26
27
28
29
30
|
# File 'lib/ci_scripts/helpers.rb', line 25
def timed_run(name)
log_info(name)
t = Time.now
yield
log_success("#{(Time.now - t).round(2)}s\n ")
end
|
#unindent(s) ⇒ Object
72
73
74
75
|
# File 'lib/ci_scripts/helpers.rb', line 72
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
|