Top Level Namespace
Defined Under Namespace
Modules: CIScripts, Demo, Docker, Files, Git, Go, Ruby
Instance Method Summary
collapse
Instance Method Details
#capture_command(*options) ⇒ Object
38
39
40
|
# File 'lib/ci_scripts/helpers.rb', line 38
def capture_command(*options)
Open3.capture2(*options)
end
|
#classify(s) ⇒ Object
78
79
80
81
82
|
# File 'lib/ci_scripts/helpers.rb', line 78
def classify(s)
s = s.to_s.split('_').collect(&:capitalize).join
s[0] = s[0].capitalize
s
end
|
#command(*options) ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/ci_scripts/helpers.rb', line 23
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
53
54
55
56
57
58
|
# File 'lib/ci_scripts/helpers.rb', line 53
def env_check(key, value)
unless ENV[key]
puts "Setting #{key} to #{value}"
ENV[key] = value
end
end
|
#env_fetch(key, default = nil) ⇒ Object
69
70
71
72
73
74
75
|
# File 'lib/ci_scripts/helpers.rb', line 69
def env_fetch(key, default = nil)
if ENV[key]
ENV[key]
else
default
end
end
|
#env_require(key) ⇒ Object
60
61
62
63
64
65
66
67
|
# File 'lib/ci_scripts/helpers.rb', line 60
def env_require(key)
val = ENV[key]
if val.nil?
log_error "Required environment variable #{key} not set"
exit 1
end
val
end
|
#installed?(binary) ⇒ Boolean
48
49
50
|
# File 'lib/ci_scripts/helpers.rb', line 48
def installed?(binary)
test_command?("command", "-v", binary)
end
|
#log_error(s) ⇒ Object
13
14
15
|
# File 'lib/ci_scripts/helpers.rb', line 13
def log_error(s)
puts("\x1b[31m#{s}\x1b[0m")
end
|
#log_info(s) ⇒ Object
5
6
7
|
# File 'lib/ci_scripts/helpers.rb', line 5
def log_info(s)
puts("\x1b[34m#{s}\x1b[0m")
end
|
#log_success(s) ⇒ Object
9
10
11
|
# File 'lib/ci_scripts/helpers.rb', line 9
def log_success(s)
puts("\x1b[32m#{s}\x1b[0m")
end
|
#nice_exit(code, msg = "Something happened") ⇒ Object
17
18
19
20
|
# File 'lib/ci_scripts/helpers.rb', line 17
def nice_exit(code, msg = "Something happened")
log_error(msg)
exit code
end
|
#test_command?(*options) ⇒ Boolean
43
44
45
46
|
# File 'lib/ci_scripts/helpers.rb', line 43
def test_command?(*options)
system(*options, out: File::NULL)
$CHILD_STATUS == 0
end
|
#timed_run(name) ⇒ Object
31
32
33
34
35
36
|
# File 'lib/ci_scripts/helpers.rb', line 31
def timed_run(name)
log_info(name)
t = Time.now
yield
log_success("#{(Time.now - t).round(2)}s\n ")
end
|
#unindent(s) ⇒ Object
84
85
86
87
|
# File 'lib/ci_scripts/helpers.rb', line 84
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
|