uuid 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/README.rdoc +6 -0
- data/lib/uuid.rb +22 -11
- data/test/test-uuid.rb +10 -0
- data/uuid.gemspec +1 -1
- metadata +5 -10
data/CHANGELOG
CHANGED
data/README.rdoc
CHANGED
@@ -68,6 +68,12 @@ writable, the file is created as <tt>.ruby-uuid</tt> in the home directory.
|
|
68
68
|
If you need to create the file with a different mode, use UUID#state_file
|
69
69
|
before running the UUID generator.
|
70
70
|
|
71
|
+
Note: If you are running on a shared host where the state file is not shared
|
72
|
+
between processes, or persisted across restarts (e.g. Heroku, Google App
|
73
|
+
Engine) you can simple turn it off:
|
74
|
+
|
75
|
+
UUID.state_file = false
|
76
|
+
|
71
77
|
State files are not portable across machines.
|
72
78
|
|
73
79
|
|
data/lib/uuid.rb
CHANGED
@@ -132,7 +132,7 @@ class UUID
|
|
132
132
|
#
|
133
133
|
# State files are not portable across machines.
|
134
134
|
def self.state_file(mode = 0644)
|
135
|
-
return @state_file
|
135
|
+
return @state_file unless @state_file.nil?
|
136
136
|
|
137
137
|
@mode = mode
|
138
138
|
|
@@ -159,7 +159,11 @@ class UUID
|
|
159
159
|
end
|
160
160
|
|
161
161
|
##
|
162
|
-
# Specify the path of the state file.
|
162
|
+
# Specify the path of the state file. Use this if you need a different
|
163
|
+
# location for your state file.
|
164
|
+
#
|
165
|
+
# Set to false if your system cannot use a state file (e.g. many shared
|
166
|
+
# hosts).
|
163
167
|
def self.state_file=(path)
|
164
168
|
@state_file = path
|
165
169
|
end
|
@@ -180,15 +184,18 @@ class UUID
|
|
180
184
|
@last_clock = (Time.now.to_f * CLOCK_MULTIPLIER).to_i
|
181
185
|
@mutex = Mutex.new
|
182
186
|
|
183
|
-
|
187
|
+
state_file = self.class.state_file
|
188
|
+
if state_file && File.size?(state_file) then
|
184
189
|
next_sequence
|
185
190
|
else
|
186
191
|
@mac = Mac.addr.gsub(/:|-/, '').hex & 0x7FFFFFFFFFFF
|
187
192
|
fail "Cannot determine MAC address from any available interface, tried with #{Mac.addr}" if @mac == 0
|
188
193
|
@sequence = rand 0x10000
|
189
194
|
|
190
|
-
|
191
|
-
|
195
|
+
if state_file
|
196
|
+
open_lock 'w' do |io|
|
197
|
+
write_state io
|
198
|
+
end
|
192
199
|
end
|
193
200
|
end
|
194
201
|
end
|
@@ -244,15 +251,19 @@ class UUID
|
|
244
251
|
##
|
245
252
|
# Updates the state file with a new sequence number.
|
246
253
|
def next_sequence
|
247
|
-
|
248
|
-
|
254
|
+
if self.class.state_file
|
255
|
+
open_lock 'r+' do |io|
|
256
|
+
@mac, @sequence, @last_clock = read_state(io)
|
249
257
|
|
250
|
-
|
251
|
-
|
258
|
+
io.rewind
|
259
|
+
io.truncate 0
|
252
260
|
|
253
|
-
|
261
|
+
@sequence += 1
|
254
262
|
|
255
|
-
|
263
|
+
write_state io
|
264
|
+
end
|
265
|
+
else
|
266
|
+
@sequence += 1
|
256
267
|
end
|
257
268
|
rescue Errno::ENOENT
|
258
269
|
open_lock 'w' do |io|
|
data/test/test-uuid.rb
CHANGED
@@ -21,6 +21,16 @@ class TestUUID < Test::Unit::TestCase
|
|
21
21
|
assert_equal path, UUID.state_file
|
22
22
|
end
|
23
23
|
|
24
|
+
def test_with_no_state_file
|
25
|
+
UUID.state_file = false
|
26
|
+
assert !UUID.state_file
|
27
|
+
uuid = UUID.new
|
28
|
+
assert_match(/\A[\da-f]{32}\z/i, uuid.generate(:compact))
|
29
|
+
seq = uuid.next_sequence
|
30
|
+
assert_equal seq + 1, uuid.next_sequence
|
31
|
+
assert !UUID.state_file
|
32
|
+
end
|
33
|
+
|
24
34
|
def test_instance_generate
|
25
35
|
uuid = UUID.new
|
26
36
|
assert_match(/\A[\da-f]{32}\z/i, uuid.generate(:compact))
|
data/uuid.gemspec
CHANGED
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.
|
4
|
+
version: 2.2.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: 2010-
|
13
|
+
date: 2010-02-18 00:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -23,10 +23,7 @@ dependencies:
|
|
23
23
|
- !ruby/object:Gem::Version
|
24
24
|
version: "1.0"
|
25
25
|
version:
|
26
|
-
description:
|
27
|
-
UUID generator for producing universally unique identifiers based on RFC 4122
|
28
|
-
(http://www.ietf.org/rfc/rfc4122.txt).
|
29
|
-
|
26
|
+
description: UUID generator for producing universally unique identifiers based on RFC 4122 (http://www.ietf.org/rfc/rfc4122.txt).
|
30
27
|
email: assaf@labnotes.org
|
31
28
|
executables: []
|
32
29
|
|
@@ -45,8 +42,6 @@ files:
|
|
45
42
|
- uuid.gemspec
|
46
43
|
has_rdoc: true
|
47
44
|
homepage: http://github.com/assaf/uuid
|
48
|
-
licenses: []
|
49
|
-
|
50
45
|
post_install_message:
|
51
46
|
rdoc_options:
|
52
47
|
- --main
|
@@ -71,9 +66,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
66
|
requirements: []
|
72
67
|
|
73
68
|
rubyforge_project:
|
74
|
-
rubygems_version: 1.3.
|
69
|
+
rubygems_version: 1.3.1
|
75
70
|
signing_key:
|
76
|
-
specification_version:
|
71
|
+
specification_version: 2
|
77
72
|
summary: UUID generator
|
78
73
|
test_files: []
|
79
74
|
|