Sha256: 67e7e5d29fd9f5a9a4cc5c6d85ccb6428bfe3184bac630153ca7ee58796ef607

Contents?: true

Size: 682 Bytes

Versions: 1

Compression:

Stored size: 682 Bytes

Contents

require 'tempfile'
require 'socket'

module Dklet::Util
  module_function

  def human_timestamp(t = Time.now)
    t.strftime("%Y%m%d%H%M%S")
  end

  def tmpfile_for(str, prefix: 'dklet-tmp')
    file = Tempfile.new(prefix)
    file.write str
    file.close # save to disk
    # unlink清理问题:引用进程结束时自动删除?👍 
    file.path
  end

  def host_ip
    Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address
  end

  def single_line?(cmds)
    cmds = cmds.chomp
    return false if cmds.is_a? Array
    return false if cmds =~ /\n/
    return true if cmds =~ /^\s*(bash|sh)/ 
    return false if cmds =~ /.+;/
    true
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dklet-0.1.5 lib/dklet/util.rb