uuid 2.0.2 → 2.1.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 +3 -0
- data/Rakefile +18 -51
- data/lib/uuid.rb +26 -2
- data/test/test-uuid.rb +24 -4
- data/uuid.gemspec +2 -3
- metadata +4 -4
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
@@ -1,15 +1,11 @@
|
|
1
|
-
# Adapted from the rake Rakefile.
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
1
|
require 'rake/testtask'
|
5
2
|
require 'rake/rdoctask'
|
6
|
-
require 'rake/gempackagetask'
|
7
3
|
|
8
4
|
|
9
|
-
spec = Gem::Specification.load(File.
|
5
|
+
spec = Gem::Specification.load(File.expand_path("uuid.gemspec", File.dirname(__FILE__)))
|
10
6
|
|
11
7
|
desc "Default Task"
|
12
|
-
task
|
8
|
+
task :default => :test
|
13
9
|
|
14
10
|
|
15
11
|
desc "If you're building from sources, run this task first to setup the necessary dependencies"
|
@@ -39,55 +35,26 @@ end
|
|
39
35
|
|
40
36
|
# Create the documentation.
|
41
37
|
Rake::RDocTask.new do |rdoc|
|
42
|
-
rdoc.
|
43
|
-
rdoc.
|
44
|
-
rdoc.title = "UUID generator"
|
38
|
+
rdoc.rdoc_files.include "README.rdoc", "lib/**/*.rb"
|
39
|
+
rdoc.options = spec.rdoc_options
|
45
40
|
end
|
46
41
|
|
47
42
|
|
48
|
-
gem = Rake::GemPackageTask.new(spec) do |pkg|
|
49
|
-
pkg.need_tar = true
|
50
|
-
pkg.need_zip = true
|
51
|
-
end
|
52
|
-
|
53
|
-
desc "Install the package locally"
|
54
|
-
task 'install'=>['setup', 'package'] do |task|
|
55
|
-
rb_bin = File.expand_path(Config::CONFIG['ruby_install_name'], Config::CONFIG['bindir'])
|
56
|
-
args = [rb_bin, '-S', 'gem', 'install', "pkg/#{spec.name}-#{spec.version}.gem"]
|
57
|
-
windows = Config::CONFIG['host_os'] =~ /windows|cygwin|bccwin|cygwin|djgpp|mingw|mswin|wince/i
|
58
|
-
args.unshift('sudo') unless windows || ENV['GEM_HOME']
|
59
|
-
sh args.map{ |a| a.inspect }.join(' ')
|
60
|
-
end
|
61
|
-
|
62
|
-
desc "Uninstall previously installed packaged"
|
63
|
-
task 'uninstall' do |task|
|
64
|
-
rb_bin = File.expand_path(Config::CONFIG['ruby_install_name'], Config::CONFIG['bindir'])
|
65
|
-
args = [rb_bin, '-S', 'gem', 'install', spec.name, '-v', spec.version.to_s]
|
66
|
-
windows = Config::CONFIG['host_os'] =~ /windows|cygwin|bccwin|cygwin|djgpp|mingw|mswin|wince/i
|
67
|
-
args.unshift('sudo') unless windows || ENV['GEM_HOME']
|
68
|
-
sh args.map{ |a| a.inspect }.join(' ')
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
task 'release'=>['setup', 'test', 'package'] do
|
73
|
-
|
74
|
-
require 'rubyforge'
|
75
|
-
changes = File.read('CHANGELOG')[/\d+.\d+.\d+.*\n((:?^[^\n]+\n)*)/]
|
76
|
-
File.open '.changes', 'w' do |file|
|
77
|
-
file.write changes
|
78
|
-
end
|
79
43
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
44
|
+
desc "Push new release to gemcutter and git tag"
|
45
|
+
task :push do
|
46
|
+
sh "git push"
|
47
|
+
puts "Tagging version #{spec.version} .."
|
48
|
+
sh "git tag v#{spec.version}"
|
49
|
+
sh "git push --tag"
|
50
|
+
puts "Building and pushing gem .."
|
51
|
+
sh "gem build #{spec.name}.gemspec"
|
52
|
+
sh "gem push #{spec.name}-#{spec.version}.gem"
|
89
53
|
end
|
90
54
|
|
91
|
-
|
92
|
-
|
55
|
+
desc "Install #{spec.name} locally"
|
56
|
+
task :install do
|
57
|
+
sh "gem build #{spec.name}.gemspec"
|
58
|
+
sudo = "sudo" unless File.writable?( Gem::ConfigMap[:bindir])
|
59
|
+
sh "#{sudo} gem install #{spec.name}-#{spec.version}.gem"
|
93
60
|
end
|
data/lib/uuid.rb
CHANGED
@@ -59,7 +59,16 @@ require 'macaddr'
|
|
59
59
|
|
60
60
|
class UUID
|
61
61
|
|
62
|
-
|
62
|
+
# Version number.
|
63
|
+
module Version
|
64
|
+
version = Gem::Specification.load(File.expand_path("../uuid.gemspec", File.dirname(__FILE__))).version.to_s.split(".").map { |i| i.to_i }
|
65
|
+
MAJOR = version[0]
|
66
|
+
MINOR = version[1]
|
67
|
+
PATCH = version[2]
|
68
|
+
STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
|
69
|
+
end
|
70
|
+
|
71
|
+
VERSION = Version::STRING
|
63
72
|
|
64
73
|
##
|
65
74
|
# Clock multiplier. Converts Time (resolution: seconds) to UUID clock
|
@@ -149,6 +158,21 @@ class UUID
|
|
149
158
|
@state_file
|
150
159
|
end
|
151
160
|
|
161
|
+
##
|
162
|
+
# Specify the path of the state file.
|
163
|
+
def self.state_file=(path)
|
164
|
+
@state_file = path
|
165
|
+
end
|
166
|
+
|
167
|
+
##
|
168
|
+
# Returns true if +uuid+ is in compact, default or urn formats. Does not
|
169
|
+
# validate the layout (RFC 4122 section 4) of the UUID.
|
170
|
+
def self.validate(uuid)
|
171
|
+
return true if uuid =~ /\A[\da-f]{32}\z/i
|
172
|
+
return true if
|
173
|
+
uuid =~ /\A(urn:uuid:)?[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}\z/i
|
174
|
+
end
|
175
|
+
|
152
176
|
##
|
153
177
|
# Create a new UUID generator. You really only need to do this once.
|
154
178
|
def initialize
|
@@ -277,5 +301,5 @@ protected
|
|
277
301
|
|
278
302
|
io.write [mac1, mac2, @sequence, @last_clock].pack(STATE_FILE_FORMAT)
|
279
303
|
end
|
280
|
-
|
304
|
+
|
281
305
|
end
|
data/test/test-uuid.rb
CHANGED
@@ -14,7 +14,13 @@ class TestUUID < Test::Unit::TestCase
|
|
14
14
|
UUID.new.generate
|
15
15
|
File.exist?(path)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
|
+
def test_state_file_specify
|
19
|
+
path = File.join("path", "to", "ruby-uuid")
|
20
|
+
UUID.state_file = path
|
21
|
+
assert_equal path, UUID.state_file
|
22
|
+
end
|
23
|
+
|
18
24
|
def test_instance_generate
|
19
25
|
uuid = UUID.new
|
20
26
|
assert_match(/\A[\da-f]{32}\z/i, uuid.generate(:compact))
|
@@ -32,7 +38,7 @@ class TestUUID < Test::Unit::TestCase
|
|
32
38
|
assert_equal 'invalid UUID format :unknown', e.message
|
33
39
|
end
|
34
40
|
|
35
|
-
def test_class_generate
|
41
|
+
def test_class_generate
|
36
42
|
assert_match(/\A[\da-f]{32}\z/i, UUID.generate(:compact))
|
37
43
|
|
38
44
|
assert_match(/\A[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}\z/i,
|
@@ -47,6 +53,20 @@ class TestUUID < Test::Unit::TestCase
|
|
47
53
|
assert_equal 'invalid UUID format :unknown', e.message
|
48
54
|
end
|
49
55
|
|
56
|
+
def test_class_validate
|
57
|
+
assert !UUID.validate('')
|
58
|
+
|
59
|
+
assert UUID.validate('01234567abcd8901efab234567890123'), 'compact'
|
60
|
+
assert UUID.validate('01234567-abcd-8901-efab-234567890123'), 'default'
|
61
|
+
assert UUID.validate('urn:uuid:01234567-abcd-8901-efab-234567890123'),
|
62
|
+
'urn'
|
63
|
+
|
64
|
+
assert UUID.validate('01234567ABCD8901EFAB234567890123'), 'compact'
|
65
|
+
assert UUID.validate('01234567-ABCD-8901-EFAB-234567890123'), 'default'
|
66
|
+
assert UUID.validate('urn:uuid:01234567-ABCD-8901-EFAB-234567890123'),
|
67
|
+
'urn'
|
68
|
+
end
|
69
|
+
|
50
70
|
def test_monotonic
|
51
71
|
seen = {}
|
52
72
|
uuid_gen = UUID.new
|
@@ -57,7 +77,7 @@ class TestUUID < Test::Unit::TestCase
|
|
57
77
|
seen[uuid] = true
|
58
78
|
end
|
59
79
|
end
|
60
|
-
|
80
|
+
|
61
81
|
def test_same_mac
|
62
82
|
class << foo = UUID.new
|
63
83
|
attr_reader :mac
|
@@ -67,7 +87,7 @@ class TestUUID < Test::Unit::TestCase
|
|
67
87
|
end
|
68
88
|
assert_equal foo.mac, bar.mac
|
69
89
|
end
|
70
|
-
|
90
|
+
|
71
91
|
def test_increasing_sequence
|
72
92
|
class << foo = UUID.new
|
73
93
|
attr_reader :sequence
|
data/uuid.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
spec = Gem::Specification.new do |spec|
|
2
2
|
spec.name = 'uuid'
|
3
|
-
spec.version = '2.0
|
3
|
+
spec.version = '2.1.0'
|
4
4
|
spec.summary = "UUID generator"
|
5
5
|
spec.description = <<-EOF
|
6
6
|
UUID generator for producing universally unique identifiers based on RFC 4122
|
@@ -10,9 +10,8 @@ EOF
|
|
10
10
|
spec.authors << 'Assaf Arkin' << 'Eric Hodel'
|
11
11
|
spec.email = 'assaf@labnotes.org'
|
12
12
|
spec.homepage = 'http://github.com/assaf/uuid'
|
13
|
-
spec.rubyforge_project = 'reliable-msg'
|
14
13
|
|
15
|
-
spec.files = Dir['{bin,test,lib,docs}/**/*'
|
14
|
+
spec.files = Dir['{bin,test,lib,docs}/**/*'] + ['README.rdoc', 'MIT-LICENSE', 'Rakefile', 'CHANGELOG', 'uuid.gemspec']
|
16
15
|
spec.has_rdoc = true
|
17
16
|
spec.rdoc_options << '--main' << 'README.rdoc' << '--title' << 'UUID generator' << '--line-numbers'
|
18
17
|
'--webcvs' << 'http://github.com/assaf/uuid'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uuid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Assaf Arkin
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-
|
13
|
+
date: 2009-12-16 00:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -70,8 +70,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
version:
|
71
71
|
requirements: []
|
72
72
|
|
73
|
-
rubyforge_project:
|
74
|
-
rubygems_version: 1.3.
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.3.5
|
75
75
|
signing_key:
|
76
76
|
specification_version: 3
|
77
77
|
summary: UUID generator
|