Sha256: f18daf0bedc8d8c951c300d5747568be7a514dc87403a6a3c484a414c13f593b

Contents?: true

Size: 819 Bytes

Versions: 4

Compression:

Stored size: 819 Bytes

Contents

require 'singleton'
require 'digest/md5'
class RemoteTable
  class Hasher
    include ::Singleton
    def hash(row)
      normalized_hash = if RUBY_VERSION >= '1.9'
        row.keys.sort.inject(::Hash.new) do |memo, k|
          normalized_k = k.to_s.toutf8
          normalized_v = row[k].respond_to?(:to_s) ? row[k].to_s.toutf8 : row[k]
          memo[normalized_k] = normalized_v
          memo
        end
      else
        ::Hash.new.replace(row)
      end
      # sabshere 1/21/11 may currently break across versions of ruby
      # ruby-1.8.7-p174 > Marshal.dump({'a' => '1'})
      #  => "\004\b{\006\"\006a\"\0061" 
      # ruby-1.9.2-p0 > Marshal.dump({'a' => '1'})
      # => "\x04\b{\x06I\"\x06a\x06:\x06ETI\"\x061\x06;\x00T"
      ::Digest::MD5.hexdigest ::Marshal.dump(normalized_hash)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
remote_table-1.0.3 lib/remote_table/hasher.rb
remote_table-1.0.2 lib/remote_table/hasher.rb
remote_table-1.0.1 lib/remote_table/hasher.rb
remote_table-1.0.0 lib/remote_table/hasher.rb