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.
Files changed (9) hide show
  1. data/CHANGELOG +32 -19
  2. data/MIT-LICENSE +1 -1
  3. data/README.rdoc +103 -0
  4. data/Rakefile +65 -185
  5. data/lib/uuid.rb +212 -326
  6. data/test/test-uuid.rb +82 -52
  7. metadata +53 -36
  8. data/README +0 -81
  9. data/bin/uuid-setup +0 -7
@@ -1,52 +1,82 @@
1
- #
2
- # = test-uuid.rb - UUID generator test cases
3
- #
4
- # Author:: Assaf Arkin assaf@labnotes.org
5
- # Documentation:: http://trac.labnotes.org/cgi-bin/trac.cgi/wiki/Ruby/UuidGenerator
6
- # Copyright:: Copyright (c) 2005,2007 Assaf Arkin
7
- # License:: MIT and/or Creative Commons Attribution-ShareAlike
8
- #
9
- #--
10
- #++
11
-
12
-
13
- require 'test/unit'
14
- require 'uuid'
15
-
16
- class TestUUID < Test::Unit::TestCase
17
-
18
- def setup
19
- end
20
-
21
- def teardown
22
- end
23
-
24
- def test_format
25
- 10.times do
26
- uuid = UUID.new :compact
27
- assert uuid =~ /^[0-9a-fA-F]{32}$/, "UUID does not conform to :compact format"
28
- assert uuid =~ UUID::REGEXP_COMPACT, "UUID does not conform to :compact format"
29
- uuid = UUID.new :default
30
- assert uuid =~ /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/, "UUID does not conform to :default format"
31
- assert uuid =~ UUID::REGEXP, "UUID does not conform to :compact format"
32
- assert uuid =~ UUID::REGEXP_FULL, "UUID does not conform to :compact format"
33
- uuid = UUID.new :urn
34
- assert uuid =~ /^urn:uuid:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/i, "UUID does not conform to :urn format"
35
- assert uuid =~ UUID::REGEXP, "UUID does not conform to :compact format"
36
- end
37
- end
38
-
39
- def test_monotonic
40
- count = 100000
41
- seen = {}
42
- count.times do |i|
43
- uuid = UUID.new
44
- assert !seen.has_key?(uuid), "UUID repeated"
45
- seen[uuid] = true
46
- print '.' if (i % 10000) == 0
47
- STDOUT.flush
48
- end
49
- end
50
-
51
- end
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: 1.0.4
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
- test_files: []
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
- extra_rdoc_files:
48
- - README
49
- executables:
50
- - uuid-setup
51
- extensions: []
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
- dependencies: []
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
-
@@ -1,7 +0,0 @@
1
- begin
2
- require 'uuid'
3
- rescue LoadError
4
- require 'rubygems'
5
- require 'uuid'
6
- end
7
- UUID::setup