uuid 1.0.4 → 2.0.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 +32 -19
- data/MIT-LICENSE +1 -1
- data/README.rdoc +103 -0
- data/Rakefile +65 -185
- data/lib/uuid.rb +212 -326
- data/test/test-uuid.rb +82 -52
- metadata +53 -36
- data/README +0 -81
- data/bin/uuid-setup +0 -7
data/test/test-uuid.rb
CHANGED
@@ -1,52 +1,82 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
uuid
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
1
|
+
# Author:: Assaf Arkin assaf@labnotes.org
|
2
|
+
# Eric Hodel drbrain@segment7.net
|
3
|
+
# Copyright:: Copyright (c) 2005-2008 Assaf Arkin, Eric Hodel
|
4
|
+
# License:: MIT and/or Creative Commons Attribution-ShareAlike
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
require 'uuid'
|
8
|
+
|
9
|
+
class TestUUID < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def test_state_file_creation
|
12
|
+
path = UUID.state_file
|
13
|
+
File.delete path if File.exist?(path)
|
14
|
+
UUID.new.generate
|
15
|
+
File.exist?(path)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_instance_generate
|
19
|
+
uuid = UUID.new
|
20
|
+
assert_match(/\A[\da-f]{32}\z/i, uuid.generate(:compact))
|
21
|
+
|
22
|
+
assert_match(/\A[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}\z/i,
|
23
|
+
uuid.generate(:default))
|
24
|
+
|
25
|
+
assert_match(/^urn:uuid:[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}\z/i,
|
26
|
+
uuid.generate(:urn))
|
27
|
+
|
28
|
+
e = assert_raise ArgumentError do
|
29
|
+
uuid.generate :unknown
|
30
|
+
end
|
31
|
+
|
32
|
+
assert_equal 'invalid UUID format :unknown', e.message
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_class_generate uuid = UUID.new
|
36
|
+
assert_match(/\A[\da-f]{32}\z/i, UUID.generate(:compact))
|
37
|
+
|
38
|
+
assert_match(/\A[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}\z/i,
|
39
|
+
UUID.generate(:default))
|
40
|
+
|
41
|
+
assert_match(/^urn:uuid:[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}\z/i,
|
42
|
+
UUID.generate(:urn))
|
43
|
+
|
44
|
+
e = assert_raise ArgumentError do
|
45
|
+
UUID.generate :unknown
|
46
|
+
end
|
47
|
+
assert_equal 'invalid UUID format :unknown', e.message
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_monotonic
|
51
|
+
seen = {}
|
52
|
+
uuid_gen = UUID.new
|
53
|
+
|
54
|
+
20_000.times do
|
55
|
+
uuid = uuid_gen.generate
|
56
|
+
assert !seen.has_key?(uuid), "UUID repeated"
|
57
|
+
seen[uuid] = true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_same_mac
|
62
|
+
class << foo = UUID.new
|
63
|
+
attr_reader :mac
|
64
|
+
end
|
65
|
+
class << bar = UUID.new
|
66
|
+
attr_reader :mac
|
67
|
+
end
|
68
|
+
assert_equal foo.mac, bar.mac
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_increasing_sequence
|
72
|
+
class << foo = UUID.new
|
73
|
+
attr_reader :sequence
|
74
|
+
end
|
75
|
+
class << bar = UUID.new
|
76
|
+
attr_reader :sequence
|
77
|
+
end
|
78
|
+
assert_equal foo.sequence + 1, bar.sequence
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
metadata
CHANGED
@@ -1,56 +1,73 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: uuid
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version:
|
7
|
-
date: 2007-08-28 00:00:00 -07:00
|
8
|
-
summary: UUID generator
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: assaf@labnotes.org
|
12
|
-
homepage: http://trac.labnotes.org/cgi-bin/trac.cgi/wiki/Ruby/UuidGenerator
|
13
|
-
rubyforge_project: reliable-msg
|
14
|
-
description: UUID generator for producing universally unique identifiers based on RFC 4122 (http://www.ietf.org/rfc/rfc4122.txt).
|
15
|
-
autorequire: uuid.rb
|
16
|
-
default_executable: uuid-setup
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 2.0.0
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Assaf Arkin
|
8
|
+
- Eric Hodel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2008-08-28 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: macaddr
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "1.0"
|
25
|
+
version:
|
26
|
+
description: UUID generator for producing universally unique identifiers based on RFC 4122 (http://www.ietf.org/rfc/rfc4122.txt).
|
27
|
+
email: assaf@labnotes.org
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- README.rdoc
|
34
|
+
- MIT-LICENSE
|
31
35
|
files:
|
32
|
-
- bin/uuid-setup
|
33
36
|
- test/test-uuid.rb
|
34
37
|
- lib/uuid.rb
|
35
|
-
- README
|
38
|
+
- README.rdoc
|
36
39
|
- MIT-LICENSE
|
37
40
|
- Rakefile
|
38
41
|
- CHANGELOG
|
39
|
-
|
40
|
-
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/assaf/uuid
|
44
|
+
post_install_message:
|
41
45
|
rdoc_options:
|
42
46
|
- --main
|
43
|
-
- README
|
47
|
+
- README.rdoc
|
44
48
|
- --title
|
45
49
|
- UUID generator
|
46
50
|
- --line-numbers
|
47
|
-
|
48
|
-
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
53
65
|
requirements: []
|
54
66
|
|
55
|
-
|
67
|
+
rubyforge_project: reliable-msg
|
68
|
+
rubygems_version: 1.2.0
|
69
|
+
signing_key:
|
70
|
+
specification_version: 2
|
71
|
+
summary: UUID generator
|
72
|
+
test_files: []
|
56
73
|
|
data/README
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
= UUID Generator
|
2
|
-
|
3
|
-
Generates universally unique identifiers (UUIDs) for use in distributed
|
4
|
-
applications. Based on {RFC 4122}[http://www.ietf.org/rfc/rfc4122.txt].
|
5
|
-
|
6
|
-
|
7
|
-
== Download
|
8
|
-
|
9
|
-
The latest version of the UUID generator can be found in the Reliable
|
10
|
-
Messaging project
|
11
|
-
|
12
|
-
* http://rubyforge.org/projects/reliable-msg/
|
13
|
-
|
14
|
-
For more information
|
15
|
-
|
16
|
-
* http://trac.labnotes.org/cgi-bin/trac.cgi/wiki/Ruby/UuidGenerator
|
17
|
-
|
18
|
-
|
19
|
-
== Installation
|
20
|
-
|
21
|
-
You can download the sources directly, or install the GEM package
|
22
|
-
(recommended) with
|
23
|
-
|
24
|
-
gem install uuid
|
25
|
-
|
26
|
-
Once installed, create a <tt>uuid.state</tt> file by running
|
27
|
-
|
28
|
-
uuid-setup
|
29
|
-
|
30
|
-
|
31
|
-
== Example
|
32
|
-
|
33
|
-
require_gem 'uuid'
|
34
|
-
|
35
|
-
10.times do
|
36
|
-
p UUID.new
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
== UUID state file
|
41
|
-
|
42
|
-
The UUID generator uses a state file (<tt>uuid.state</tt>) to hold the
|
43
|
-
MAC address and sequence number.
|
44
|
-
|
45
|
-
The MAC address is used to generate identifiers that are unique to your
|
46
|
-
machine, preventing conflicts in distributed applications. The MAC
|
47
|
-
address is six bytes (48 bit) long. It is automatically extracted from
|
48
|
-
one of the network cards on your machine by running +ipconfig+
|
49
|
-
(Windows) or +ifconfig+ (Linux, UNIX, et al). You can override the MAC
|
50
|
-
address by editing the <tt>uuid.state</tt> file yourself.
|
51
|
-
|
52
|
-
The sequence number is incremented each time the UUID generator is
|
53
|
-
first used by the application, to prevent multiple processes from
|
54
|
-
generating the same set of identifiers, and deal with changes to the
|
55
|
-
system clock.
|
56
|
-
|
57
|
-
The UUID state file is created with
|
58
|
-
|
59
|
-
uuid-setup
|
60
|
-
|
61
|
-
It is created in the installation directory. If you installed the UUID
|
62
|
-
generator as a Gem, it will be created in the Gem's directory. However,
|
63
|
-
the UUID generator will look for the <tt>uuid.state</tt> first in the
|
64
|
-
local directory, and then in the installation directory. You can use
|
65
|
-
that to maintain separate state files for different applications.
|
66
|
-
However, make sure they generate unique identifiers by using different
|
67
|
-
MAC addresses in each state file.
|
68
|
-
|
69
|
-
|
70
|
-
== Change log
|
71
|
-
|
72
|
-
:include: CHANGELOG
|
73
|
-
|
74
|
-
|
75
|
-
== License
|
76
|
-
|
77
|
-
This package is licensed under the MIT license and/or the {Creative
|
78
|
-
Commons Attribution-ShareAlike}[http://creativecommons.org/licenses/by-sa/2.5/legalcode].
|
79
|
-
|
80
|
-
:include: MIT-LICENSE
|
81
|
-
|