module Bdsync::Utils
Public Class Methods
caller_info(level)
click to toggle source
# File lib/bdsync/utils.rb, line 29 def self.caller_info level info = caller[level].match(%r{([^/]+):(\d+):in `(.+)'}) "#{info.captures[0]}:#{info.captures[1]} - #{info.captures[2]}" end
file_md5(file_path)
click to toggle source
# File lib/bdsync/utils.rb, line 25 def self.file_md5 file_path Digest::MD5.file(file_path).hexdigest end
md5(s)
click to toggle source
# File lib/bdsync/utils.rb, line 21 def self.md5(s) Digest::MD5.hexdigest(s) end
timestamp()
click to toggle source
Examples:
puts Utils.timestamp
> 2019-12-11.16-15-57
puts Utils.timestamp[0...10]
.delete(“-”) > 20191211
# File lib/bdsync/utils.rb, line 13 def self.timestamp ts = Time.now.to_s[0..18] ts[10] = "." ts[13] = ts[16] = "-" ts end
try_lock() { || ... }
click to toggle source
# File lib/bdsync/utils.rb, line 34 def self.try_lock &block File.open(__FILE__, 'r') { |f| return if !f.flock(File::LOCK_EX | File::LOCK_NB) yield } end