module Dklet::Util
Public Instance Methods
gen_password(len = 10)
click to toggle source
secure
# File lib/dklet/util.rb, line 43 def gen_password(len = 10) SecureRandom.alphanumeric(len) end
host_ip()
click to toggle source
# File lib/dklet/util.rb, line 21 def host_ip Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address end
host_os()
click to toggle source
# File lib/dklet/util.rb, line 25 def host_os ::OS end
human_timestamp(t = Time.now)
click to toggle source
# File lib/dklet/util.rb, line 9 def human_timestamp(t = Time.now) t.strftime("%Y%m%d%H%M%S") end
on_mac?()
click to toggle source
# File lib/dklet/util.rb, line 29 def on_mac? host_os.mac? end
single_line?(cmds)
click to toggle source
# File lib/dklet/util.rb, line 33 def single_line?(cmds) return false if cmds.is_a? Array cmds = cmds.chomp return false if cmds =~ /\n/ return true if cmds =~ /^\s*(bash|sh)/ return false if cmds =~ /.+;/ true end
tmpfile_for(str, prefix: 'dklet-tmp')
click to toggle source
# File lib/dklet/util.rb, line 13 def tmpfile_for(str, prefix: 'dklet-tmp') file = Tempfile.new(prefix) file.write str file.close # save to disk # unlink清理问题:引用进程结束时自动删除?👍 file.path end