simple_uuid 0.2.0 → 0.3.0
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.
- data/CHANGELOG +2 -0
- data/Manifest +1 -0
- data/lib/simple_uuid.rb +19 -7
- data/simple_uuid.gemspec +15 -15
- data/test/test_uuid.rb +7 -0
- metadata +6 -6
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
data/lib/simple_uuid.rb
CHANGED
@@ -20,7 +20,7 @@ module SimpleUUID
|
|
20
20
|
|
21
21
|
VARIANT = 0b1000_0000_0000_0000
|
22
22
|
|
23
|
-
def initialize(bytes = nil)
|
23
|
+
def initialize(bytes = nil, opts = {})
|
24
24
|
case bytes
|
25
25
|
when self.class # UUID
|
26
26
|
@bytes = bytes.to_s
|
@@ -48,16 +48,28 @@ module SimpleUUID
|
|
48
48
|
when NilClass, Time
|
49
49
|
time = (bytes || Time).stamp * 10 + GREGORIAN_EPOCH_OFFSET
|
50
50
|
# See http://github.com/spectra/ruby-uuid/
|
51
|
-
|
51
|
+
byte_array = [
|
52
52
|
time & 0xFFFF_FFFF,
|
53
53
|
time >> 32,
|
54
54
|
((time >> 48) & 0x0FFF) | 0x1000,
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
]
|
56
|
+
|
57
|
+
# Top 3 bytes reserved
|
58
|
+
if opts[:randomize] == false
|
59
|
+
byte_array += [
|
60
|
+
0 | VARIANT,
|
61
|
+
0,
|
62
|
+
0
|
63
|
+
]
|
64
|
+
else
|
65
|
+
byte_array += [
|
66
|
+
rand(2**13) | VARIANT,
|
67
|
+
rand(2**16),
|
68
|
+
rand(2**32)
|
69
|
+
]
|
70
|
+
end
|
60
71
|
|
72
|
+
@bytes = byte_array.pack("NnnnnN")
|
61
73
|
else
|
62
74
|
raise TypeError, "Expected #{bytes.inspect} to cast to a #{self.class} (unknown source class)"
|
63
75
|
end
|
data/simple_uuid.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "0.
|
4
|
+
s.name = "simple_uuid"
|
5
|
+
s.version = "0.3.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0.8") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = [
|
9
|
-
s.date =
|
10
|
-
s.description =
|
11
|
-
s.email =
|
12
|
-
s.extra_rdoc_files = [
|
13
|
-
s.files = [
|
14
|
-
s.homepage =
|
15
|
-
s.rdoc_options = [
|
16
|
-
s.require_paths = [
|
17
|
-
s.rubyforge_project =
|
18
|
-
s.rubygems_version =
|
19
|
-
s.summary =
|
20
|
-
s.test_files = [
|
8
|
+
s.authors = ["Ryan King, Evan Weaver"]
|
9
|
+
s.date = "2012-11-27"
|
10
|
+
s.description = "Simple, scalable UUID generation."
|
11
|
+
s.email = "ryan@twitter.com"
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.rdoc", "lib/simple_uuid.rb"]
|
13
|
+
s.files = ["CHANGELOG", "LICENSE", "Manifest", "README.rdoc", "Rakefile", "lib/simple_uuid.rb", "simple_uuid.gemspec", "test/test_uuid.rb"]
|
14
|
+
s.homepage = "http://fauna.github.com/fauna/simple_uuid/"
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Simple_uuid", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = "fauna"
|
18
|
+
s.rubygems_version = "1.8.24"
|
19
|
+
s.summary = "Simple, scalable UUID generation."
|
20
|
+
s.test_files = ["test/test_uuid.rb"]
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
23
23
|
s.specification_version = 3
|
data/test/test_uuid.rb
CHANGED
@@ -59,4 +59,11 @@ class UUIDTest < Test::Unit::TestCase
|
|
59
59
|
uuid = UUID.new
|
60
60
|
assert_equal uuid.send(:total_usecs), UUID.total_usecs(uuid.bytes)
|
61
61
|
end
|
62
|
+
|
63
|
+
def test_no_jitter
|
64
|
+
t = Time.now
|
65
|
+
|
66
|
+
assert_not_equal UUID.new(t), UUID.new(t)
|
67
|
+
assert_equal UUID.new(t, randomize: false), UUID.new(t, randomize: false)
|
68
|
+
end
|
62
69
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_uuid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan King, Evan Weaver
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-11-27 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: Simple, scalable UUID generation.
|
@@ -36,8 +36,8 @@ files:
|
|
36
36
|
- README.rdoc
|
37
37
|
- Rakefile
|
38
38
|
- lib/simple_uuid.rb
|
39
|
-
- test/test_uuid.rb
|
40
39
|
- simple_uuid.gemspec
|
40
|
+
- test/test_uuid.rb
|
41
41
|
homepage: http://fauna.github.com/fauna/simple_uuid/
|
42
42
|
licenses: []
|
43
43
|
|
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
73
|
requirements: []
|
74
74
|
|
75
75
|
rubyforge_project: fauna
|
76
|
-
rubygems_version: 1.8.
|
76
|
+
rubygems_version: 1.8.24
|
77
77
|
signing_key:
|
78
78
|
specification_version: 3
|
79
79
|
summary: Simple, scalable UUID generation.
|