Sha256: af268f29a84298460c84d751d14178c3c2a3c592331016d5e8eb1be1e3bf2996
Contents?: true
Size: 1.32 KB
Versions: 3
Compression:
Stored size: 1.32 KB
Contents
module Misc def self.digest_str(obj) if obj.respond_to?(:digest_str) obj.digest_str else case obj when String #'\'' << obj << '\'' if Path === obj || ! Open.exists?(obj) '\'' << obj << '\'' else Misc.file_md5(obj) end when Integer, Symbol obj.to_s when Array '[' << obj.inject(""){|acc,o| acc.empty? ? Misc.digest_str(o) : acc << ', ' << Misc.digest_str(o) } << ']' when Hash '{' << obj.inject(""){|acc,p| s = Misc.digest_str(p.first) << "=" << Misc.digest_str(p.last); acc.empty? ? s : acc << ', ' << s } << '}' when Integer obj.to_s when Float if obj % 1 == 0 obj.to_i elsif obj.abs > 10 "%.1f" % obj elsif obj.abs > 1 "%.3f" % obj else "%.6f" % obj end when TrueClass "true" when FalseClass "false" else obj.inspect end end end def self.digest(obj) str = Misc.digest_str(obj) hash = Digest::MD5.hexdigest(str) Log.debug "Digest #{hash} - #{str}" hash end def self.file_md5(file) file = file.find if Path === file #md5file = file + '.md5' Persist.persist("MD5:#{file}", :string) do Digest::MD5.file(file).hexdigest end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
scout-gear-6.0.0 | lib/scout/misc/digest.rb |
scout-gear-5.2.0 | lib/scout/misc/digest.rb |
scout-gear-5.1.1 | lib/scout/misc/digest.rb |