Module: Bdsync::Utils
- Defined in:
- lib/bdsync/utils.rb
Class Method Summary collapse
- .caller_info(level) ⇒ Object
- .md5(s) ⇒ Object
-
.timestamp ⇒ Object
Examples:.
- .try_lock(&block) ⇒ Object
Class Method Details
.caller_info(level) ⇒ Object
25 26 27 28 |
# File 'lib/bdsync/utils.rb', line 25 def self.caller_info level info = caller[level].match(%r{([^/]+):(\d+):in `(.+)'}) "#{info.captures[0]}:#{info.captures[1]} - #{info.captures[2]}" end |
.md5(s) ⇒ Object
21 22 23 |
# File 'lib/bdsync/utils.rb', line 21 def self.md5(s) Digest::MD5.hexdigest(s) end |
.timestamp ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/bdsync/utils.rb', line 13 def self. ts = Time.now.to_s[0..18] ts[10] = "." ts[13] = ts[16] = "-" ts end |
.try_lock(&block) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/bdsync/utils.rb', line 30 def self.try_lock &block File.open(__FILE__, 'r') { |f| return if !f.flock(File::LOCK_EX | File::LOCK_NB) yield } end |