simple_uuid 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Manifest +0 -1
- data/README.rdoc +7 -1
- data/Rakefile +1 -3
- data/lib/simple_uuid.rb +22 -5
- data/simple_uuid.gemspec +10 -11
- data/test/test_uuid.rb +21 -1
- metadata +8 -10
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
data/README.rdoc
CHANGED
@@ -22,7 +22,13 @@ Install the gem:
|
|
22
22
|
|
23
23
|
== Usage
|
24
24
|
|
25
|
-
|
25
|
+
# Creating and getting a timestamp from the UUID
|
26
|
+
uuid = SimpleUUID::UUID.new => <UUID#2278170300 .... >
|
27
|
+
uuid.to_time => Thu Aug 18 19:15:16 -0400 2011
|
28
|
+
|
29
|
+
# Given raw bytes from a source such as cassandra (using bytes from an existing UUID as an example)
|
30
|
+
bytes = SimpleUUID::UUID.new.bytes
|
31
|
+
SimpleUUID::UUID.to_time(bytes) => Thu Aug 18 19:15:16 -0400 2011
|
26
32
|
|
27
33
|
== Reporting problems
|
28
34
|
|
data/Rakefile
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
require 'echoe'
|
3
2
|
|
4
3
|
Echoe.new('simple_uuid') do |e|
|
@@ -7,6 +6,5 @@ Echoe.new('simple_uuid') do |e|
|
|
7
6
|
e.email = 'ryan@twitter.com'
|
8
7
|
e.rubygems_version = ">= 0.8"
|
9
8
|
e.project = "fauna"
|
10
|
-
e.
|
11
|
-
e.docs_host = "blog.evanweaver.com:~/www/bax/public/files/doc/"
|
9
|
+
e.retain_gemspec = true
|
12
10
|
end
|
data/lib/simple_uuid.rb
CHANGED
@@ -11,6 +11,7 @@ end
|
|
11
11
|
module SimpleUUID
|
12
12
|
# UUID format version 1, as specified in RFC 4122, with jitter in place of the mac address and sequence counter.
|
13
13
|
class UUID
|
14
|
+
include Comparable
|
14
15
|
|
15
16
|
class InvalidVersion < StandardError #:nodoc:
|
16
17
|
end
|
@@ -105,7 +106,7 @@ module SimpleUUID
|
|
105
106
|
|
106
107
|
def inspect(long = false)
|
107
108
|
"<UUID##{object_id} time: #{
|
108
|
-
|
109
|
+
to_time.inspect
|
109
110
|
}, usecs: #{
|
110
111
|
usecs
|
111
112
|
} jitter: #{
|
@@ -126,11 +127,27 @@ module SimpleUUID
|
|
126
127
|
other.respond_to?(:bytes) && bytes == other.bytes
|
127
128
|
end
|
128
129
|
|
129
|
-
|
130
|
+
# Given raw bytes, return a time object
|
131
|
+
def self.to_time(bytes)
|
132
|
+
usecs = total_usecs(bytes)
|
133
|
+
Time.at(usecs / 1_000_000, usecs % 1_000_000)
|
134
|
+
end
|
135
|
+
|
136
|
+
# Return a time object
|
137
|
+
def to_time
|
138
|
+
Time.at(total_usecs / 1_000_000, total_usecs % 1_000_000)
|
139
|
+
end
|
140
|
+
|
141
|
+
# Given raw bytes, return the total_usecs
|
142
|
+
def self.total_usecs(bytes)
|
143
|
+
elements = bytes.unpack("Nnn")
|
144
|
+
(elements[0] + (elements[1] << 32) + ((elements[2] & 0x0FFF) << 48) - GREGORIAN_EPOCH_OFFSET) / 10
|
145
|
+
end
|
130
146
|
|
147
|
+
private
|
148
|
+
|
131
149
|
def total_usecs
|
132
|
-
|
133
|
-
(elements[0] + (elements[1] << 32) + ((elements[2] & 0x0FFF) << 48) - GREGORIAN_EPOCH_OFFSET) / 10
|
150
|
+
@total_usecs ||= self.class.total_usecs(@bytes)
|
134
151
|
end
|
135
152
|
end
|
136
|
-
end
|
153
|
+
end
|
data/simple_uuid.gemspec
CHANGED
@@ -2,25 +2,24 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{simple_uuid}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.2.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 = %q{2011-
|
8
|
+
s.authors = [%q{Ryan King, Evan Weaver}]
|
9
|
+
s.date = %q{2011-08-19}
|
10
10
|
s.description = %q{Simple, scalable UUID generation.}
|
11
11
|
s.email = %q{ryan@twitter.com}
|
12
|
-
s.extra_rdoc_files = [
|
13
|
-
s.files = [
|
14
|
-
s.homepage = %q{http://
|
15
|
-
s.rdoc_options = [
|
16
|
-
s.require_paths = [
|
12
|
+
s.extra_rdoc_files = [%q{CHANGELOG}, %q{LICENSE}, %q{README.rdoc}, %q{lib/simple_uuid.rb}]
|
13
|
+
s.files = [%q{CHANGELOG}, %q{LICENSE}, %q{Manifest}, %q{README.rdoc}, %q{Rakefile}, %q{lib/simple_uuid.rb}, %q{test/test_uuid.rb}, %q{simple_uuid.gemspec}]
|
14
|
+
s.homepage = %q{http://fauna.github.com/fauna/simple_uuid/}
|
15
|
+
s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Simple_uuid}, %q{--main}, %q{README.rdoc}]
|
16
|
+
s.require_paths = [%q{lib}]
|
17
17
|
s.rubyforge_project = %q{fauna}
|
18
|
-
s.rubygems_version = %q{1.
|
18
|
+
s.rubygems_version = %q{1.8.5}
|
19
19
|
s.summary = %q{Simple, scalable UUID generation.}
|
20
|
-
s.test_files = [
|
20
|
+
s.test_files = [%q{test/test_uuid.rb}]
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
23
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
23
|
s.specification_version = 3
|
25
24
|
|
26
25
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
data/test/test_uuid.rb
CHANGED
@@ -39,4 +39,24 @@ class UUIDTest < Test::Unit::TestCase
|
|
39
39
|
b = a.dup
|
40
40
|
assert_equal a, b
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
|
+
def test_comparison
|
44
|
+
current_uuid = UUID.new(Time.now)
|
45
|
+
future_uuid = UUID.new(Time.now + rand(60))
|
46
|
+
|
47
|
+
assert current_uuid < future_uuid
|
48
|
+
assert current_uuid >= current_uuid
|
49
|
+
assert future_uuid >= current_uuid
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_to_time
|
53
|
+
ts = Time.new
|
54
|
+
uuid = UUID.new(ts)
|
55
|
+
assert_equal ts, uuid.to_time
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_total_usecs
|
59
|
+
uuid = UUID.new
|
60
|
+
assert_equal uuid.send(:total_usecs), UUID.total_usecs(uuid.bytes)
|
61
|
+
end
|
62
|
+
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:
|
5
|
-
prerelease:
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 1
|
9
8
|
- 2
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan King, Evan Weaver
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
18
|
+
date: 2011-08-19 00:00:00 Z
|
20
19
|
dependencies: []
|
21
20
|
|
22
21
|
description: Simple, scalable UUID generation.
|
@@ -37,10 +36,9 @@ files:
|
|
37
36
|
- README.rdoc
|
38
37
|
- Rakefile
|
39
38
|
- lib/simple_uuid.rb
|
40
|
-
- simple_uuid.gemspec
|
41
39
|
- test/test_uuid.rb
|
42
|
-
|
43
|
-
homepage: http://
|
40
|
+
- simple_uuid.gemspec
|
41
|
+
homepage: http://fauna.github.com/fauna/simple_uuid/
|
44
42
|
licenses: []
|
45
43
|
|
46
44
|
post_install_message:
|
@@ -75,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
73
|
requirements: []
|
76
74
|
|
77
75
|
rubyforge_project: fauna
|
78
|
-
rubygems_version: 1.
|
76
|
+
rubygems_version: 1.8.5
|
79
77
|
signing_key:
|
80
78
|
specification_version: 3
|
81
79
|
summary: Simple, scalable UUID generation.
|