hash_digest 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODI5OGYwMmEyMTQ1ZjMyNmNiMjcyMmIyMTU3NTBmMWFmNjgzMDVmNA==
4
+ NTY4NDk1MDA3Yjc5ODZhNzI3ZmRkNjEzN2U4YjAxNzg4ZTFlNGEzMA==
5
5
  data.tar.gz: !binary |-
6
- ZmVlMDRkN2MxOTY4MDRiMWJjNjMyOGNmMmUwMDdlMWQyYzAyM2VlZg==
6
+ OGViMWNlNTE5NjA5M2VjMzg1YjBhM2IxNmY2N2U2ZjY1NTRhYmViZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjllMmZlNjc3Zjg4M2Q2YzA5OTFlOTA4MWUzYjA0MDQ5YzA3MjRhNmU4ZWZk
10
- NWM0Yjg4MTM3NzdjNTYwMjNmMTA0ODFiMmJjMTY5N2MyZWI0MDE2MDdkYjVm
11
- MTcwNmY1Y2Y5MmUyYzAxNjIzOWM2MzY5ZDQ3ODY1MzZhZTgyOGE=
9
+ MDk2YzFjZjg3MmYwM2U0OTdkMjc5YjA3MjRiZTZiZDI0ZTYwZDYxNzVkZDdm
10
+ ZDgyOTA1YTk3ZjM5MzMzMDQ2YTU2ZTk4YmU3MTJiZjY0YzNlNGVlZjVhMDY3
11
+ ZTc5NWY4NTJlMGM2MGU5ZDY2NGVmYzMzM2I2OTk0OWZlMDg0OTE=
12
12
  data.tar.gz: !binary |-
13
- MTk0MDNkMzk5ZTMzOTNkMGY5OTJhOWMzZDhjNGFhY2ZiY2VkYTNkZTc0OTE2
14
- MWJiZTFiMzdmNTgwMGE1ZjVkNGQ1YWQ4MTdlZmRhOWNiMGYxYTM0ZTgzMjUw
15
- YzlkZDNhYzFjNWFkMzIxMDQzNGIzNTFhNmMzNjVmMDg5ZDYwMzg=
13
+ Y2NhYzQ4M2VmZWI0Yzg5NDg5ZDJhNTNkZGRjNTgwMmQ5NzliYzE5YmNiY2Uz
14
+ ZGQ3M2U3NWU5MGNlNDZlZmM2ODMyOWVjOTUxOWQwOTE2MjExMGViZmNjNTAw
15
+ YmY4Y2Q0M2JiNmEwMTQ1OTNiYTExOGI0YWM1ZmUwYmQ4OWQwYzM=
data/.gitignore CHANGED
@@ -2,3 +2,5 @@
2
2
  .bundle
3
3
  Gemfile.lock
4
4
  pkg/*
5
+ doc/
6
+ .yardoc/
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ 1.1.1 / 2014-01-02
2
+
3
+ * Bug fixes
4
+
5
+ * Fix compatibility with JRuby - thanks @towerhe https://github.com/seamusabshere/remote_table/issues/13
6
+ * Corrected README to latest and greatest
7
+
1
8
  1.1.0 / 2014-01-01
2
9
 
3
10
  * Breaking changes
data/README.markdown CHANGED
@@ -1,25 +1,62 @@
1
1
  # HashDigest
2
2
 
3
- Generates MD5 digests of Hashes (and Arrays) indifferent to key type and ordering.
3
+ Generates non-cryptographic digests of Hashes (and Arrays) indifferent to key type (string or symbol) and ordering.
4
4
 
5
- Useful for hashing rows in a 2-dimensional table.
5
+ Extracted from [`RemoteTable`](https://github.com/seamusabshere/remote_table).
6
6
 
7
- Used by the [remote_table](https://github.com/seamusabshere/remote_table) gem.
7
+ ## Note plz
8
+
9
+ 1. You should use `HashDigest.digest2` for new applications. `hexdigest` is legacy.
10
+ 2. `digest2`, unlike its predecessor, is CASE SENSITIVE.
8
11
 
9
12
  ## Example
10
13
 
11
14
  ### Indifferent to key type
12
15
 
13
- HashDigest.hexdigest(:a => 1) #=> '3872c9ae3f427af0be0ead09d07ae2cf'
14
- HashDigest.hexdigest('a' => 1) #=> '3872c9ae3f427af0be0ead09d07ae2cf'
16
+ >> HashDigest.digest2(:a => 1)
17
+ => "1s05qdo"
18
+ >> HashDigest.digest2('a' => 1)
19
+ => "1s05qdo"
15
20
 
16
21
  ### Indifferent to key order
17
22
 
18
- HashDigest.hexdigest(:a => 1, 'b' => 2) == HashDigest.hexdigest('a' => 1, :b => 2) # true
19
- HashDigest.hexdigest(:a => 1, 'b' => 2) == HashDigest.hexdigest(:b => 2, 'a' => 1) # true
23
+ >> HashDigest.digest2(:a => 1, 'b' => 2)
24
+ => "fkqncr"
25
+ >> HashDigest.digest2(:b => 2, 'a' => 1)
26
+ => "fkqncr"
27
+
28
+ ## Speed
29
+
30
+ If you're **not** on JRuby, having [`EscapeUtils`](https://github.com/brianmario/escape_utils) in your `Gemfile` will make things much faster.
31
+
32
+ ### With EscapeUtils (MRI, doesn't work on JRuby)
33
+
34
+ HashDigest.digest2 2492 i/100ms
35
+ HashDigest.hexdigest 2276 i/100ms
36
+
37
+ ### With stdlib's CGI (JRuby)
38
+
39
+ HashDigest.digest2 645 i/100ms
40
+ HashDigest.hexdigest 213 i/100ms
41
+
42
+ ### With stdlib's CGI (MRI)
43
+
44
+ HashDigest.digest2 531 i/100ms
45
+ HashDigest.hexdigest 513 i/100ms
20
46
 
21
47
  ## Algorithm
22
48
 
49
+ ### digest2 (current)
50
+
51
+ 1. Represent the hash as a URL querystring
52
+ 2. Sort by key
53
+ 3. [MurmurHash3](http://en.wikipedia.org/wiki/MurmurHash)
54
+ 4. Convert to base 36 to save space
55
+
56
+ Note: non-cryptographic and variable length. CASE SENSITIVE.
57
+
58
+ ### hexdigest (deprecated)
59
+
23
60
  Basically represent the hash as a URL querystring, ordered by key, and MD5 that.
24
61
 
25
62
  1. Stringify keys
@@ -31,10 +68,8 @@ To digest an array, just pretend it's a hash with keys like 1, 2, 3, etc.
31
68
 
32
69
  ## Potential issues
33
70
 
34
- * Uses MD5 (not cryptographically awesome)
35
- * Uses ActiveSupport's <tt>#to_query</tt> method to create a digestible string like "foo=bar&baz=bam" (slow)
36
71
  * Meant for flat hashes, e.g. { :a => 1, :b => 2 } and not { :x => { :y => :z } }
37
72
 
38
73
  ## Copyright
39
74
 
40
- Copyright 2011 Seamus Abshere
75
+ Copyright 2013 Seamus Abshere
data/Rakefile CHANGED
@@ -8,4 +8,9 @@ Rake::TestTask.new(:test) do |test|
8
8
  test.verbose = true
9
9
  end
10
10
 
11
+ require 'yard'
12
+ YARD::Rake::YardocTask.new do |y|
13
+ y.options << '--no-private'
14
+ end
15
+
11
16
  task :default => :test
data/hash_digest.gemspec CHANGED
@@ -19,10 +19,14 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_runtime_dependency 'murmurhash3'
22
- s.add_runtime_dependency 'escape_utils'
23
22
 
24
23
  s.add_development_dependency 'minitest'
25
24
  s.add_development_dependency 'rake'
26
25
  s.add_development_dependency 'activesupport'
27
26
  s.add_development_dependency 'benchmark-ips'
27
+ s.add_development_dependency 'yard'
28
+
29
+ if ENV['TEST_ESCAPE_UTILS'] == 'true'
30
+ s.add_development_dependency 'escape_utils'
31
+ end
28
32
  end
data/lib/hash_digest.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'digest/md5'
2
2
  require 'murmurhash3'
3
- require 'escape_utils'
3
+ # see below for requiring either cgi (on JRuby) or escape_utils (if available)
4
4
 
5
5
  require "hash_digest/version"
6
6
 
@@ -38,6 +38,22 @@ module HashDigest
38
38
  def self.hexdigest(obj)
39
39
  ::Digest::MD5.hexdigest as_digest1(obj)
40
40
  end
41
+
42
+ # CGI escaping engine
43
+
44
+ if RUBY_PLATFORM == 'java'
45
+ require 'cgi'
46
+ def self.escape_url(str); ::CGI.escape(str) end
47
+ else
48
+ begin
49
+ # MUCH faster than stdlib's cgi
50
+ require 'escape_utils'
51
+ def self.escape_url(str); ::EscapeUtils.escape_url(str) end
52
+ rescue LoadError
53
+ require 'cgi'
54
+ def self.escape_url(str); ::CGI.escape(str) end
55
+ end
56
+ end
41
57
  end
42
58
 
43
59
  # EVERYTHING BELOW IS COPIED FROM ACTIVESUPPORT 4.0.2
@@ -70,7 +86,6 @@ end
70
86
 
71
87
  class Object
72
88
  def to_hash_digest_query(key)
73
- # "#{::CGI.escape(key.to_hash_digest_param)}=#{::CGI.escape(to_hash_digest_param)}"
74
- "#{::EscapeUtils.escape_url(key.to_hash_digest_param)}=#{::EscapeUtils.escape_url(to_hash_digest_param)}"
89
+ "#{::HashDigest.escape_url(key.to_hash_digest_param)}=#{::HashDigest.escape_url(to_hash_digest_param)}"
75
90
  end
76
91
  end
@@ -1,3 +1,3 @@
1
1
  module HashDigest
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_digest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-01 00:00:00.000000000 Z
11
+ date: 2014-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: murmurhash3
@@ -25,13 +25,13 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: escape_utils
28
+ name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
- type: :runtime
34
+ type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: minitest
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ! '>='
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: activesupport
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ! '>='
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: activesupport
70
+ name: benchmark-ips
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ! '>='
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: benchmark-ips
84
+ name: yard
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ! '>='