uuidtools 2.1.5 → 2.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: ebf635496c48e173f29b09b4719846a83ab15d19
4
- data.tar.gz: cdf833d1f98797978853ee0d700277704ec9ad86
2
+ SHA256:
3
+ metadata.gz: a5cf7d8f6def3ddb0c325cfe8d2dec0404b73996c69f559888d74dad4f6519f1
4
+ data.tar.gz: 4ba7a0931d37d6f14f664e230d38610995d281167ab1c0e0ed2ea6355c93a060
5
5
  SHA512:
6
- metadata.gz: 33c70bffe56bd16152da53299f283067ec0087070a3b4a94347a01d30bceada03b879e3cf2df697e168deff94789c5c69933641f77707764d187debf52bad7e7
7
- data.tar.gz: dd36f05b2ec9f696c6c1a1c413df01f0372e504be3c09d4db77340c7db3bd68253e326b835913ef2cf9f35fd534ccb777ea00d043b47a272da46a461607bc3fe
6
+ metadata.gz: f9ac42163867349a27f20100c859be1103dec0b5c402f7630371d8debadb8a760b399f4f4369a941111987ca53ab68775947431f21ce29c7d267efb2a88fcc2c
7
+ data.tar.gz: 20b1d43a62100484f52844a919ba4683ca774da910e572acb865d599af5b6ad795180418746039b7a9b2f24942350a00414ca3309c6987dbf93085330017842c
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == UUIDTools 2.2.0
2
+ * drop support for ruby < 2.3
3
+ * use Integer vs Fixnum
4
+ * performance improvements
1
5
  == UUIDTools 2.1.5
2
6
  * fixed issue with ip command vs ifconfig
3
7
  * dumped RubyForge related cruft
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://secure.travis-ci.org/sporkmonger/uuidtools.svg)](http://travis-ci.org/sporkmonger/uuidtools)
2
+
1
3
  # UUIDTools
2
4
 
3
5
  <dl>
@@ -7,10 +9,6 @@
7
9
  <dt>License</dt><dd>Apache 2.0</dd>
8
10
  </dl>
9
11
 
10
- [![Build Status](https://secure.travis-ci.org/sporkmonger/uuidtools.png)](http://travis-ci.org/sporkmonger/uuidtools)
11
- [![Dependency Status](https://gemnasium.com/sporkmonger/uuidtools.png)](https://gemnasium.com/sporkmonger/uuidtools)
12
- [![Gittip Donate](http://img.shields.io/gittip/sporkmonger.png)](https://www.gittip.com/sporkmonger/ "Support Open Source Development w/ Gittip")
13
-
14
12
  # Description
15
13
 
16
14
  UUIDTools was designed to be a simple library for generating any
@@ -164,7 +164,7 @@ module UUIDTools
164
164
  clock_seq_hi_and_reserved = uuid_components[3].to_i(16)
165
165
  clock_seq_low = uuid_components[4].to_i(16)
166
166
  nodes = []
167
- for i in 0..5
167
+ 6.times do |i|
168
168
  nodes << uuid_components[5][(i * 2)..(i * 2) + 1].to_i(16)
169
169
  end
170
170
  return self.new(time_low, time_mid, time_hi_and_version,
@@ -178,19 +178,52 @@ module UUIDTools
178
178
  raise TypeError,
179
179
  "Expected String, got #{raw_string.class.name} instead."
180
180
  end
181
- integer = self.convert_byte_string_to_int(raw_string)
182
181
 
183
- time_low = (integer >> 96) & 0xFFFFFFFF
184
- time_mid = (integer >> 80) & 0xFFFF
185
- time_hi_and_version = (integer >> 64) & 0xFFFF
186
- clock_seq_hi_and_reserved = (integer >> 56) & 0xFF
187
- clock_seq_low = (integer >> 48) & 0xFF
182
+ if raw_string.respond_to?(:force_encoding)
183
+ raw_string.force_encoding(Encoding::ASCII_8BIT)
184
+ end
185
+
186
+ raw_length = raw_string.length
187
+ if raw_length < 16
188
+ # Option A: Enforce raw_string be 16 characters (More strict)
189
+ #raise ArgumentError,
190
+ # "Expected 16 bytes, got #{raw_string.length} instead."
191
+
192
+ # Option B: Pad raw_string to 16 characters (Compatible with existing behavior)
193
+ raw_string = raw_string.rjust(16, "\0")
194
+ elsif raw_length > 16
195
+ # NOTE: As per "Option B" above, existing behavior would use the lower
196
+ # 128-bits of an overly long raw_string instead of using the upper 128-bits.
197
+ start_index = raw_length - 16
198
+ raw_string = raw_string[start_index...raw_length]
199
+ end
200
+
201
+ raw_bytes = []
202
+ if raw_string[0].respond_to? :ord
203
+ for i in 0...raw_string.size
204
+ raw_bytes << raw_string[i].ord
205
+ end
206
+ else
207
+ raw_bytes = raw_string
208
+ end
209
+
210
+ time_low = ((raw_bytes[0] << 24) +
211
+ (raw_bytes[1] << 16) +
212
+ (raw_bytes[2] << 8) +
213
+ raw_bytes[3])
214
+ time_mid = ((raw_bytes[4] << 8) +
215
+ raw_bytes[5])
216
+ time_hi_and_version = ((raw_bytes[6] << 8) +
217
+ raw_bytes[7])
218
+ clock_seq_hi_and_reserved = raw_bytes[8]
219
+ clock_seq_low = raw_bytes[9]
188
220
  nodes = []
189
- for i in 0..5
190
- nodes << ((integer >> (40 - (i * 8))) & 0xFF)
221
+ for i in 10...16
222
+ nodes << raw_bytes[i]
191
223
  end
224
+
192
225
  return self.new(time_low, time_mid, time_hi_and_version,
193
- clock_seq_hi_and_reserved, clock_seq_low, nodes)
226
+ clock_seq_hi_and_reserved, clock_seq_low, nodes)
194
227
  end
195
228
 
196
229
  ##
@@ -200,17 +233,42 @@ module UUIDTools
200
233
  raise ArgumentError,
201
234
  "Expected Integer, got #{uuid_int.class.name} instead."
202
235
  end
203
- return self.parse_raw(self.convert_int_to_byte_string(uuid_int, 16))
236
+
237
+ time_low = (uuid_int >> 96) & 0xFFFFFFFF
238
+ time_mid = (uuid_int >> 80) & 0xFFFF
239
+ time_hi_and_version = (uuid_int >> 64) & 0xFFFF
240
+ clock_seq_hi_and_reserved = (uuid_int >> 56) & 0xFF
241
+ clock_seq_low = (uuid_int >> 48) & 0xFF
242
+ nodes = []
243
+ for i in 0..5
244
+ nodes << ((uuid_int >> (40 - (i * 8))) & 0xFF)
245
+ end
246
+
247
+ return self.new(time_low, time_mid, time_hi_and_version,
248
+ clock_seq_hi_and_reserved, clock_seq_low, nodes)
204
249
  end
205
250
 
206
251
  ##
207
252
  # Parse a UUID from a hexdigest String.
208
- def self.parse_hexdigest(uuid_hexdigest)
209
- unless uuid_hexdigest.kind_of?(String)
253
+ def self.parse_hexdigest(uuid_hex)
254
+ unless uuid_hex.kind_of?(String)
210
255
  raise ArgumentError,
211
- "Expected String, got #{uuid_hexdigest.class.name} instead."
256
+ "Expected String, got #{uuid_hex.class.name} instead."
257
+ end
258
+
259
+ time_low = uuid_hex[0...8].to_i(16)
260
+ time_mid = uuid_hex[8...12].to_i(16)
261
+ time_hi_and_version = uuid_hex[12...16].to_i(16)
262
+ clock_seq_hi_and_reserved = uuid_hex[16...18].to_i(16)
263
+ clock_seq_low = uuid_hex[18...20].to_i(16)
264
+ nodes_string = uuid_hex[20...32]
265
+ nodes = []
266
+ for i in 0..5
267
+ nodes << nodes_string[(i * 2)..(i * 2) + 1].to_i(16)
212
268
  end
213
- return self.parse_int(uuid_hexdigest.to_i(16))
269
+
270
+ return self.new(time_low, time_mid, time_hi_and_version,
271
+ clock_seq_hi_and_reserved, clock_seq_low, nodes)
214
272
  end
215
273
 
216
274
  ##
@@ -249,7 +307,7 @@ module UUIDTools
249
307
  nodes = SecureRandom.random_bytes(6).unpack("C*")
250
308
  nodes[0] |= 0b00000001
251
309
  end
252
- for i in 0..5
310
+ 6.times do |i|
253
311
  node_id += (nodes[i] << (40 - (i * 8)))
254
312
  end
255
313
  clock_sequence = @@last_clock_sequence
@@ -405,7 +463,7 @@ module UUIDTools
405
463
  return check if check != 0
406
464
  check = self.clock_seq_low <=> other_uuid.clock_seq_low
407
465
  return check if check != 0
408
- for i in 0..5
466
+ 6.times do |i|
409
467
  if (self.nodes[i] < other_uuid.nodes[i])
410
468
  return -1
411
469
  end
@@ -486,7 +544,7 @@ module UUIDTools
486
544
  bytes = (time_low << 96) + (time_mid << 80) +
487
545
  (time_hi_and_version << 64) + (clock_seq_hi_and_reserved << 56) +
488
546
  (clock_seq_low << 48)
489
- for i in 0..5
547
+ 6.times do |i|
490
548
  bytes += (nodes[i] << (40 - (i * 8)))
491
549
  end
492
550
  bytes
@@ -500,7 +558,7 @@ module UUIDTools
500
558
  def generate_s
501
559
  result = sprintf("%8.8x-%4.4x-%4.4x-%2.2x%2.2x-", @time_low, @time_mid,
502
560
  @time_hi_and_version, @clock_seq_hi_and_reserved, @clock_seq_low);
503
- for i in 0..5
561
+ 6.times do |i|
504
562
  result << sprintf("%2.2x", @nodes[i])
505
563
  end
506
564
  return result.downcase
@@ -699,7 +757,7 @@ module UUIDTools
699
757
  if byte_string.respond_to?(:force_encoding)
700
758
  byte_string.force_encoding(Encoding::ASCII_8BIT)
701
759
  end
702
- for i in 0..(size - 1)
760
+ size.times do |i|
703
761
  byte_string << ((integer >> (((size - 1) - i) * 8)) & 0xFF)
704
762
  end
705
763
  return byte_string
@@ -711,13 +769,19 @@ module UUIDTools
711
769
  if byte_string.respond_to?(:force_encoding)
712
770
  byte_string.force_encoding(Encoding::ASCII_8BIT)
713
771
  end
772
+
714
773
  integer = 0
715
774
  size = byte_string.size
716
- for i in 0..(size - 1)
717
- ordinal = (byte_string[i].respond_to?(:ord) ?
718
- byte_string[i].ord : byte_string[i])
719
- integer += (ordinal << (((size - 1) - i) * 8))
775
+ if byte_string[0].respond_to? :ord
776
+ for i in 0...size
777
+ integer += (byte_string[i].ord << (((size - 1) - i) * 8))
778
+ end
779
+ else
780
+ for i in 0...size
781
+ integer += (byte_string[i] << (((size - 1) - i) * 8))
782
+ end
720
783
  end
784
+
721
785
  return integer
722
786
  end
723
787
  end
@@ -21,8 +21,8 @@ unless defined? UUIDTools::VERSION
21
21
  module UUIDTools
22
22
  module VERSION #:nodoc:
23
23
  MAJOR = 2
24
- MINOR = 1
25
- TINY = 5
24
+ MINOR = 2
25
+ TINY = 0
26
26
 
27
27
  STRING = [MAJOR, MINOR, TINY].join('.')
28
28
  end
@@ -94,7 +94,7 @@ describe UUIDTools::UUID, "when parsing" do
94
94
  it "should produce a sane hash value for a UUID" do
95
95
  uuid = UUIDTools::UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0])
96
96
  expect(uuid.to_i).to eql(0)
97
- expect(uuid.hash).to be_kind_of(Fixnum)
97
+ expect(uuid.hash).to be_kind_of(Integer)
98
98
  end
99
99
 
100
100
  it "should produce the correct URI for a UUID" do
@@ -125,4 +125,23 @@ describe UUIDTools::UUID, "when parsing" do
125
125
  uuid = UUIDTools::UUID.timestamp_create
126
126
  expect(UUIDTools::UUID.parse_hexdigest(uuid.hexdigest)).to eql(uuid)
127
127
  end
128
+
129
+ it "should correctly parse raw bytes" do
130
+ # NOTE: Short Input
131
+ expect(UUIDTools::UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0])).to eql(
132
+ UUIDTools::UUID.parse_raw(""))
133
+
134
+ # NOTE: Nil Input
135
+ expect(UUIDTools::UUID.parse_raw(
136
+ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
137
+ )).to be_nil_uuid
138
+
139
+ # NOTE: Realistic Input
140
+ uuid = UUIDTools::UUID.timestamp_create
141
+ expect(UUIDTools::UUID.parse_raw(uuid.raw)).to eql(uuid)
142
+
143
+ # NOTE: Long input
144
+ raw192bit = "\1\2\3\4\5\6\7\8" + uuid.raw
145
+ expect(UUIDTools::UUID.parse_raw(raw192bit)).to eql(uuid)
146
+ end
128
147
  end
@@ -1,38 +1,57 @@
1
1
  task :benchmark do
2
- require 'lib/uuidtools'
3
2
  require 'benchmark'
4
3
 
5
- # Version 1
6
- result = Benchmark.measure do
7
- 10000.times do
8
- UUID.timestamp_create.to_s
9
- end
10
- end
11
- puts "#{(10000.0 / result.real)} version 1 per second."
4
+ $LOAD_PATH.unshift File.expand_path('../..', __FILE__)
5
+ require 'lib/uuidtools'
12
6
 
13
- # Version 3
14
- result = Benchmark.measure do
15
- 10000.times do
16
- UUID.md5_create(UUID_URL_NAMESPACE,
17
- "http://www.ietf.org/rfc/rfc4122.txt").to_s
18
- end
7
+ def format_float(float)
8
+ ("%.2f" % float).rjust(9, ' ')
19
9
  end
20
- puts "#{(10000.0 / result.real)} version 3 per second."
21
10
 
22
- # Version 4
23
- result = Benchmark.measure do
24
- 10000.times do
25
- UUID.random_create.to_s
26
- end
11
+ def format_result(result, action, iterations)
12
+ $stdout.puts "#{format_float(iterations / result.real)} | #{action}"
27
13
  end
28
- puts "#{(10000.0 / result.real)} version 4 per second."
29
14
 
30
- # Version 5
31
- result = Benchmark.measure do
32
- 10000.times do
33
- UUID.sha1_create(UUID_URL_NAMESPACE,
34
- "http://www.ietf.org/rfc/rfc4122.txt").to_s
15
+ def benchmark(name, n = 10000)
16
+ result = Benchmark.measure do
17
+ n.times { yield }
35
18
  end
19
+
20
+ format_result(result, name, n)
36
21
  end
37
- puts "#{(10000.0 / result.real)} version 5 per second."
22
+
23
+ $stdout.puts ' x/second | Benchmark'
24
+ $stdout.puts '---------- -----------'
25
+
26
+ ##
27
+ # Benchmark UUID creation
28
+ namespace = UUIDTools::UUID_URL_NAMESPACE
29
+ url = "http://www.ietf.org/rfc/rfc4122.txt"
30
+
31
+ benchmark('Version 1') { UUIDTools::UUID.timestamp_create.to_s }
32
+ benchmark('Version 3') { UUIDTools::UUID.md5_create(namespace, url).to_s }
33
+ benchmark('Version 4') { UUIDTools::UUID.random_create.to_s }
34
+ benchmark('Version 5') { UUIDTools::UUID.sha1_create(namespace, url).to_s }
35
+
36
+ ##
37
+ # Benchmark UUID parsing
38
+ uuid_s = UUIDTools::UUID.random_create.to_s
39
+ benchmark('UUID::parse', 40000) { UUIDTools::UUID.parse(uuid_s) }
40
+
41
+ uuid_raw = UUIDTools::UUID.random_create.raw
42
+ benchmark('UUID::parse_raw', 40000) { UUIDTools::UUID.parse_raw(uuid_raw) }
43
+
44
+ uuid_i = UUIDTools::UUID.random_create.to_i
45
+ benchmark('UUID::parse_int', 40000) { UUIDTools::UUID.parse_int(uuid_i) }
46
+
47
+ uuid_hex = UUIDTools::UUID.random_create.hexdigest
48
+ benchmark('UUID::parse_hexdigest', 40000) { UUIDTools::UUID.parse_hexdigest(uuid_hex) }
49
+
50
+ ##
51
+ # Benchmark UUID private api
52
+ byte_string = UUIDTools::UUID.timestamp_create.raw
53
+ benchmark('UUID::convert_byte_string_to_int') { UUIDTools::UUID.convert_byte_string_to_int(byte_string) }
54
+
55
+ bigint = UUIDTools::UUID.timestamp_create.to_i
56
+ benchmark('UUID::convert_int_to_byte_string') { UUIDTools::UUID.convert_int_to_byte_string(bigint, 16) }
38
57
  end
@@ -10,6 +10,7 @@ namespace :gem do
10
10
  s.version = PKG_VERSION
11
11
  s.summary = PKG_SUMMARY
12
12
  s.description = PKG_DESCRIPTION
13
+ s.licenses = ["Apache-2.0"]
13
14
 
14
15
  s.files = PKG_FILES.to_a
15
16
 
@@ -43,14 +44,8 @@ namespace :gem do
43
44
  task :gemspec do
44
45
  spec_string = GEM_SPEC.to_ruby
45
46
 
46
- begin
47
- Thread.new { eval("$SAFE = 3\n#{spec_string}", binding) }.join
48
- rescue
49
- abort "unsafe gemspec: #{$!}"
50
- else
51
- File.open("#{GEM_SPEC.name}.gemspec", 'w') do |file|
52
- file.write spec_string
53
- end
47
+ File.open("#{GEM_SPEC.name}.gemspec", "w") do |file|
48
+ file.write spec_string
54
49
  end
55
50
  end
56
51
 
@@ -0,0 +1,42 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # stub: uuidtools 2.2.0 ruby lib
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "uuidtools".freeze
6
+ s.version = "2.2.0"
7
+
8
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
+ s.require_paths = ["lib".freeze]
10
+ s.authors = ["Bob Aman".freeze]
11
+ s.date = "2020-07-09"
12
+ s.description = "A simple universally unique ID generation library.\n".freeze
13
+ s.email = "bob@sporkmonger.com".freeze
14
+ s.extra_rdoc_files = ["README.md".freeze]
15
+ s.files = ["CHANGELOG".freeze, "LICENSE.txt".freeze, "README.md".freeze, "Rakefile".freeze, "doc".freeze, "documentation".freeze, "lib".freeze, "lib/compat".freeze, "lib/compat/securerandom.rb".freeze, "lib/uuidtools".freeze, "lib/uuidtools.rb".freeze, "lib/uuidtools/version.rb".freeze, "pkg".freeze, "spec".freeze, "spec/spec.opts".freeze, "spec/spec_helper.rb".freeze, "spec/uuidtools".freeze, "spec/uuidtools/mac_address_spec.rb".freeze, "spec/uuidtools/utility_spec.rb".freeze, "spec/uuidtools/uuid_creation_spec.rb".freeze, "spec/uuidtools/uuid_parsing_spec.rb".freeze, "tasks".freeze, "tasks/benchmark.rake".freeze, "tasks/gem.rake".freeze, "tasks/git.rake".freeze, "tasks/metrics.rake".freeze, "tasks/rspec.rake".freeze, "tasks/yard.rake".freeze, "uuidtools.gemspec".freeze, "website".freeze, "website/index.html".freeze]
16
+ s.homepage = "https://github.com/sporkmonger/uuidtools".freeze
17
+ s.licenses = ["Apache-2.0".freeze]
18
+ s.rdoc_options = ["--main".freeze, "README.md".freeze]
19
+ s.rubygems_version = "3.0.8".freeze
20
+ s.summary = "UUID generator".freeze
21
+
22
+ if s.respond_to? :specification_version then
23
+ s.specification_version = 4
24
+
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
+ s.add_development_dependency(%q<rake>.freeze, [">= 0.7.3"])
27
+ s.add_development_dependency(%q<rspec>.freeze, [">= 2.9.0"])
28
+ s.add_development_dependency(%q<yard>.freeze, [">= 0.8.2"])
29
+ s.add_development_dependency(%q<launchy>.freeze, [">= 2.0.0"])
30
+ else
31
+ s.add_dependency(%q<rake>.freeze, [">= 0.7.3"])
32
+ s.add_dependency(%q<rspec>.freeze, [">= 2.9.0"])
33
+ s.add_dependency(%q<yard>.freeze, [">= 0.8.2"])
34
+ s.add_dependency(%q<launchy>.freeze, [">= 2.0.0"])
35
+ end
36
+ else
37
+ s.add_dependency(%q<rake>.freeze, [">= 0.7.3"])
38
+ s.add_dependency(%q<rspec>.freeze, [">= 2.9.0"])
39
+ s.add_dependency(%q<yard>.freeze, [">= 0.8.2"])
40
+ s.add_dependency(%q<launchy>.freeze, [">= 2.0.0"])
41
+ end
42
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uuidtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.5
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Aman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-12 00:00:00.000000000 Z
11
+ date: 2020-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -66,8 +66,9 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 2.0.0
69
- description: |
70
- A simple universally unique ID generation library.
69
+ description: 'A simple universally unique ID generation library.
70
+
71
+ '
71
72
  email: bob@sporkmonger.com
72
73
  executables: []
73
74
  extensions: []
@@ -93,9 +94,11 @@ files:
93
94
  - tasks/metrics.rake
94
95
  - tasks/rspec.rake
95
96
  - tasks/yard.rake
97
+ - uuidtools.gemspec
96
98
  - website/index.html
97
99
  homepage: https://github.com/sporkmonger/uuidtools
98
- licenses: []
100
+ licenses:
101
+ - Apache-2.0
99
102
  metadata: {}
100
103
  post_install_message:
101
104
  rdoc_options:
@@ -114,8 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
117
  - !ruby/object:Gem::Version
115
118
  version: '0'
116
119
  requirements: []
117
- rubyforge_project:
118
- rubygems_version: 2.2.2
120
+ rubygems_version: 3.0.8
119
121
  signing_key:
120
122
  specification_version: 4
121
123
  summary: UUID generator