crimp 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f951279d5308025d1f3184b1a823a1577d13ebad
4
- data.tar.gz: 9444429cbc53f722f053815ced9db784e29a5374
2
+ SHA256:
3
+ metadata.gz: 933033b434c42dd1f1bddcae7dab3a28ca3cd59ea6f3c1c9099f7b7b94f16eb4
4
+ data.tar.gz: a48ac5e269d70ac652422d4959372acd2937df77ae3a970887642b67ee5ad4af
5
5
  SHA512:
6
- metadata.gz: f91307d9094be916d32b3e95ca5c620db68979ec5d3eb465efaa2e0876df96543d51a43fad76331d20f04baa34ed254ab355587886ad66db7453badff1afcf3b
7
- data.tar.gz: 092f330b087472fd4ebda5653ccb6ba86857597d205e71d15636562fd2ec2b2626cce2598b733d74acd7a7a637796148526f43d91e0bb569a67aee494ea3c98b
6
+ metadata.gz: b270bad70530524c0110fa9e6e80e29f95751802d7732cb5c683aa3e610d4674485ed4196384f8b6312629dc2cd64d2a60de0cce301a2dd8520f38be9735f966
7
+ data.tar.gz: 269d0964c13056187ded2be18fc748bbbe9fc9e85b8b5e67d165aa27e9a07c7ff9d8681ccfddd6bd70bbc172514e6976e881d14b9df3da2783a7e04d6d2d0e99
@@ -1 +1 @@
1
- jruby-1.7.17
1
+ jruby-1.7.23
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "crimp"
8
8
  spec.version = Crimp::VERSION
9
9
  spec.authors = ["BBC News"]
10
- spec.email = ["FutureMediaNewsRubyGems@bbc.co.uk"]
10
+ spec.email = ["D&ENewsFrameworksTeam@bbc.co.uk"]
11
11
  spec.summary = %q{Creating an md5 hash of a number, string, array, or hash in Ruby}
12
12
  spec.description = <<-EOS.gsub /^\s+/, ""
13
13
  Shamelessly lifted from http://stackoverflow.com/questions/6461812/creating-an-md5-hash-of-a-number-string-array-or-hash-in-ruby
@@ -1,6 +1,13 @@
1
1
  require 'crimp/version'
2
2
  require 'digest'
3
3
 
4
+ class Numeric
5
+ # see http://patshaughnessy.net/2014/1/9/how-big-is-a-bignum
6
+ def bignum?
7
+ self >= 4611686018427387904
8
+ end
9
+ end
10
+
4
11
  module Crimp
5
12
  def self.signature(obj)
6
13
  Digest::MD5.hexdigest stringify(obj)
@@ -44,6 +51,24 @@ module Crimp
44
51
  end
45
52
 
46
53
  def self.to_string(obj)
47
- "#{obj}#{obj.class}"
54
+ "#{obj}#{legacy_class(obj)}"
55
+ end
56
+
57
+ # This is for legacy/compatibilty reason:
58
+ #
59
+ # Ruby 2.1
60
+ # 2.class => Fixnum
61
+ # Ruby >= 2.4
62
+ # 2.class => Integer
63
+ #
64
+ # Say you have a huge number of stored keys and you migrate your app from 2.1 to >= 2.4
65
+ # this would cause a change of the signature for a subset of the keys which would be hard
66
+ # to debug especially for nested data structures.
67
+ #
68
+ def self.legacy_class(obj)
69
+ return obj.class unless obj.is_a?(Numeric)
70
+ return 'Float' if obj.is_a?(Float)
71
+ return 'Bignum' if obj.bignum?
72
+ 'Fixnum'
48
73
  end
49
74
  end
@@ -1,3 +1,3 @@
1
1
  module Crimp
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -1,17 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Crimp do
4
- let (:hash) { { a: { b: 'b', c: 'c' }, d: 'd' } }
5
- let (:hash_unordered) { { d: 'd', a: { c: 'c', b: 'b' } } }
6
- let (:array) { [1, 2, 3, [4, [5, 6]]] }
7
- let (:array_unordered) { [3, 2, 1, [[5, 6], 4]] }
4
+ let(:hash) { { a: { b: 'b', c: 'c' }, d: 'd' } }
5
+ let(:hash_with_numbers) { { a: { b: 1, c: 3.14 }, d: 'd' } }
6
+ let(:hash_unordered) { { d: 'd', a: { c: 'c', b: 'b' } } }
7
+ let(:array) { [1, 2, 3, [4, [5, 6]]] }
8
+ let(:array_unordered) { [3, 2, 1, [[5, 6], 4]] }
8
9
 
9
10
  describe '.signature' do
10
11
  context 'given a Hash' do
11
- specify { expect(subject.signature(hash)).to be_a String }
12
-
13
12
  it 'returns MD5 hash of stringified Hash' do
14
- expect(subject.signature(hash)).to eq(Digest::MD5.hexdigest(subject.stringify(hash)))
13
+ expect(subject.signature(hash)).to eq('68d07febc4f47f56fa6ef5de063a77b1')
15
14
  end
16
15
 
17
16
  it 'does not modify original hash' do
@@ -24,11 +23,15 @@ describe Crimp do
24
23
  end
25
24
  end
26
25
 
27
- context 'given an Array' do
28
- specify { expect(subject.signature(array)).to be_a String }
26
+ context 'Given an hash with numbers' do
27
+ it 'returns MD5 hash of stringified hash' do
28
+ expect(subject.signature(hash_with_numbers)).to eq 'b1fec09904b6ff36c92e3bd48234def7'
29
+ end
30
+ end
29
31
 
32
+ context 'given an Array' do
30
33
  it 'returns MD5 hash of stringified Array' do
31
- expect(subject.signature(array)).to eq(Digest::MD5.hexdigest(subject.stringify(array)))
34
+ expect(subject.signature(array)).to eq('4dc4e1161c9315db0bc43c0201b3ec05')
32
35
  end
33
36
 
34
37
  it 'does not modify original array' do
@@ -40,12 +43,28 @@ describe Crimp do
40
43
  expect(original_array).to eq(expected_array)
41
44
  end
42
45
  end
46
+
47
+ context 'Given an integer' do
48
+ it 'returns MD5 hash of an Integer' do
49
+ expect(subject.signature(123)).to eq '519d3381631851be66711f6d7dfbb4f8'
50
+ end
51
+ end
52
+
53
+ context 'Given an Bignum' do
54
+ it 'returns MD5 hash of a Bignum' do
55
+ expect(subject.signature(9999999999999999999)).to eq 'f00e75abca720e18fd4213e2a6de96c6'
56
+ end
57
+ end
58
+
59
+ context 'Given an float' do
60
+ it 'returns MD5 hash of a Float' do
61
+ expect(subject.signature(3.14)).to eq 'b07d506e3701fddd083ae9095df43218'
62
+ end
63
+ end
43
64
  end
44
65
 
45
66
  describe '.stringify' do
46
67
  context 'given a Hash' do
47
- specify { expect(subject.stringify(hash)).to be_a String }
48
-
49
68
  it 'returns equal strings for differently ordered hashes' do
50
69
  expect(subject.stringify(hash)).to eq(subject.stringify(hash_unordered))
51
70
  end
metadata CHANGED
@@ -1,167 +1,167 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crimp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - BBC News
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-25 00:00:00.000000000 Z
11
+ date: 2018-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: bundler
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
- - - ~>
17
+ - - "~>"
17
18
  - !ruby/object:Gem::Version
18
19
  version: '1.5'
19
- name: bundler
20
- prerelease: false
21
20
  type: :development
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
+ name: rake
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - '>='
31
+ - - ">="
31
32
  - !ruby/object:Gem::Version
32
33
  version: '0'
33
- name: rake
34
- prerelease: false
35
34
  type: :development
35
+ prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
+ name: rspec
42
43
  requirement: !ruby/object:Gem::Requirement
43
44
  requirements:
44
- - - '>='
45
+ - - ">="
45
46
  - !ruby/object:Gem::Version
46
47
  version: '0'
47
- name: rspec
48
- prerelease: false
49
48
  type: :development
49
+ prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
+ name: rake-rspec
56
57
  requirement: !ruby/object:Gem::Requirement
57
58
  requirements:
58
- - - '>='
59
+ - - ">="
59
60
  - !ruby/object:Gem::Version
60
61
  version: '0'
61
- name: rake-rspec
62
- prerelease: false
63
62
  type: :development
63
+ prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
+ name: rspec-nc
70
71
  requirement: !ruby/object:Gem::Requirement
71
72
  requirements:
72
- - - '>='
73
+ - - ">="
73
74
  - !ruby/object:Gem::Version
74
75
  version: '0'
75
- name: rspec-nc
76
- prerelease: false
77
76
  type: :development
77
+ prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
+ name: guard
84
85
  requirement: !ruby/object:Gem::Requirement
85
86
  requirements:
86
- - - '>='
87
+ - - ">="
87
88
  - !ruby/object:Gem::Version
88
89
  version: '0'
89
- name: guard
90
- prerelease: false
91
90
  type: :development
91
+ prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
98
99
  requirement: !ruby/object:Gem::Requirement
99
100
  requirements:
100
- - - '>='
101
+ - - ">="
101
102
  - !ruby/object:Gem::Version
102
103
  version: '0'
103
- name: guard-rspec
104
- prerelease: false
105
104
  type: :development
105
+ prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
+ name: pry
112
113
  requirement: !ruby/object:Gem::Requirement
113
114
  requirements:
114
- - - '>='
115
+ - - ">="
115
116
  - !ruby/object:Gem::Version
116
117
  version: '0'
117
- name: pry
118
- prerelease: false
119
118
  type: :development
119
+ prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
+ name: pry-remote
126
127
  requirement: !ruby/object:Gem::Requirement
127
128
  requirements:
128
- - - '>='
129
+ - - ">="
129
130
  - !ruby/object:Gem::Version
130
131
  version: '0'
131
- name: pry-remote
132
- prerelease: false
133
132
  type: :development
133
+ prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - '>='
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
+ name: pry-nav
140
141
  requirement: !ruby/object:Gem::Requirement
141
142
  requirements:
142
- - - '>='
143
+ - - ">="
143
144
  - !ruby/object:Gem::Version
144
145
  version: '0'
145
- name: pry-nav
146
- prerelease: false
147
146
  type: :development
147
+ prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - '>='
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  description: |
154
154
  Shamelessly lifted from http://stackoverflow.com/questions/6461812/creating-an-md5-hash-of-a-number-string-array-or-hash-in-ruby
155
155
  All credit should go to http://stackoverflow.com/users/394282/luke
156
156
  email:
157
- - FutureMediaNewsRubyGems@bbc.co.uk
157
+ - D&ENewsFrameworksTeam@bbc.co.uk
158
158
  executables: []
159
159
  extensions: []
160
160
  extra_rdoc_files: []
161
161
  files:
162
- - .gitignore
163
- - .ruby-version
164
- - .travis.yml
162
+ - ".gitignore"
163
+ - ".ruby-version"
164
+ - ".travis.yml"
165
165
  - Gemfile
166
166
  - Guardfile
167
167
  - LICENSE.txt
@@ -177,24 +177,24 @@ homepage: ''
177
177
  licenses:
178
178
  - MIT
179
179
  metadata: {}
180
- post_install_message:
180
+ post_install_message:
181
181
  rdoc_options: []
182
182
  require_paths:
183
183
  - lib
184
184
  required_ruby_version: !ruby/object:Gem::Requirement
185
185
  requirements:
186
- - - '>='
186
+ - - ">="
187
187
  - !ruby/object:Gem::Version
188
188
  version: '0'
189
189
  required_rubygems_version: !ruby/object:Gem::Requirement
190
190
  requirements:
191
- - - '>='
191
+ - - ">="
192
192
  - !ruby/object:Gem::Version
193
193
  version: '0'
194
194
  requirements: []
195
- rubyforge_project:
196
- rubygems_version: 2.1.9
197
- signing_key:
195
+ rubyforge_project:
196
+ rubygems_version: 2.7.6
197
+ signing_key:
198
198
  specification_version: 4
199
199
  summary: Creating an md5 hash of a number, string, array, or hash in Ruby
200
200
  test_files: