uuid 2.1.1 → 2.2.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 CHANGED
@@ -1,3 +1,6 @@
1
+ 2.2.0 (2010-02-18)
2
+ * Added: set UUID.state_file = false if you cannot use a state file (e.g. shared hosting environment)
3
+
1
4
  2.1.1 (2010-01-27)
2
5
  * Fixed bug which caused UUID.new to fail if the state file was somehow extant but empty
3
6
 
@@ -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
 
@@ -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 if @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
- if File.size?(self.class.state_file) then
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
- open_lock 'w' do |io|
191
- write_state io
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
- open_lock 'r+' do |io|
248
- @mac, @sequence, @last_clock = read_state(io)
254
+ if self.class.state_file
255
+ open_lock 'r+' do |io|
256
+ @mac, @sequence, @last_clock = read_state(io)
249
257
 
250
- io.rewind
251
- io.truncate 0
258
+ io.rewind
259
+ io.truncate 0
252
260
 
253
- @sequence += 1
261
+ @sequence += 1
254
262
 
255
- write_state io
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|
@@ -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))
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |spec|
2
2
  spec.name = 'uuid'
3
- spec.version = '2.1.1'
3
+ spec.version = '2.2.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
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.1.1
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-01-27 00:00:00 -08:00
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.5
69
+ rubygems_version: 1.3.1
75
70
  signing_key:
76
- specification_version: 3
71
+ specification_version: 2
77
72
  summary: UUID generator
78
73
  test_files: []
79
74