module AppRb::Util
Constants
- MAX_PORT
- MIN_PORT
Public Class Methods
blue(txt)
click to toggle source
# File lib/app-rb/util.rb, line 8 def self.blue(txt); "\e[0;34m#{txt}\e[0m"; end
compare_versions(a, b)
click to toggle source
# File lib/app-rb/util.rb, line 31 def self.compare_versions(a, b) parse = proc { |v| v.split(".", 3).map(&:to_i) + [v.index("-dev") ? 1 : 0] } parse.call(a) <=> parse.call(b) end
do_it(cmd)
click to toggle source
# File lib/app-rb/util.rb, line 10 def self.do_it(cmd) puts "[exec] #{cmd}" system(cmd) unless $?.success? puts red("FATAL :(") exit end end
get_free_port(user, host)
click to toggle source
# File lib/app-rb/util.rb, line 36 def self.get_free_port(user, host) port = nil 10.times do a = MIN_PORT + rand(MAX_PORT - MIN_PORT) if just_cmd("ssh #{user}@#{host} ss -ln src :#{a} | fgrep -c ':#{a}'", true) == "0" port = a break end end raise "Dont find free port :-((" unless port port end
green(txt)
click to toggle source
# File lib/app-rb/util.rb, line 7 def self.green(txt); "\e[0;32m#{txt}\e[0m"; end
just_cmd(cmd, skip_exit_status = false)
click to toggle source
# File lib/app-rb/util.rb, line 19 def self.just_cmd(cmd, skip_exit_status = false) puts "[exec] #{cmd}" output = `#{cmd}` if $?.success? || skip_exit_status output.strip else puts red(output) puts red("FATAL :(") exit end end
red(txt)
click to toggle source
# File lib/app-rb/util.rb, line 6 def self.red(txt); "\e[0;31m#{txt}\e[0m"; end
yellow(txt)
click to toggle source
# File lib/app-rb/util.rb, line 5 def self.yellow(txt); "\e[0;33m#{txt}\e[0m"; end