gn0m30-uuid 2.1.2 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,6 +1,16 @@
1
- 2.1.1 (2010-01-25)
1
+
2
+ 2.2.1 (2010-02-18)
3
+ * merged changes from assaf/uuid
4
+
5
+ 2.2.0 (2010-02-18)
6
+ * Added: set UUID.state_file = false if you cannot use a state file (e.g. shared hosting environment)
7
+
8
+ 2.1.2 (2010-01-25)
2
9
  * added the :teenie format
3
10
 
11
+ 2.1.1 (2010-01-27)
12
+ * Fixed bug which caused UUID.new to fail if the state file was somehow extant but empty
13
+
4
14
  2.1.0 (2009-12-16)
5
15
  * Added uuid.validate -- easier to implement than explain why it's wrong.
6
16
 
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2005-2008 Assaf Arkin, Eric Hodel
1
+ Copyright (c) 2005-2010 Assaf Arkin, Eric Hodel
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -73,6 +73,12 @@ writable, the file is created as <tt>.ruby-uuid</tt> in the home directory.
73
73
  If you need to create the file with a different mode, use UUID#state_file
74
74
  before running the UUID generator.
75
75
 
76
+ Note: If you are running on a shared host where the state file is not shared
77
+ between processes, or persisted across restarts (e.g. Heroku, Google App
78
+ Engine) you can simple turn it off:
79
+
80
+ UUID.state_file = false
81
+
76
82
  State files are not portable across machines.
77
83
 
78
84
 
data/gn0m30-uuid.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |spec|
2
2
  spec.name = 'gn0m30-uuid'
3
- spec.version = '2.1.2'
3
+ spec.version = '2.2.1'
4
4
  spec.summary = "UUID generator with teenie format"
5
5
  spec.description = <<-EOF
6
6
  UUID generator for producing universally unique identifiers based on RFC 4122
data/lib/uuid.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # Author:: Assaf Arkin assaf@labnotes.org
5
5
  # Eric Hodel drbrain@segment7.net
6
- # Copyright:: Copyright (c) 2005-2008 Assaf Arkin, Eric Hodel
6
+ # Copyright:: Copyright (c) 2005-2010 Assaf Arkin, Eric Hodel
7
7
  # License:: MIT and/or Creative Commons Attribution-ShareAlike
8
8
 
9
9
  require 'fileutils'
@@ -135,7 +135,7 @@ class UUID
135
135
  #
136
136
  # State files are not portable across machines.
137
137
  def self.state_file(mode = 0644)
138
- return @state_file if @state_file
138
+ return @state_file unless @state_file.nil?
139
139
 
140
140
  @mode = mode
141
141
 
@@ -162,7 +162,11 @@ class UUID
162
162
  end
163
163
 
164
164
  ##
165
- # Specify the path of the state file.
165
+ # Specify the path of the state file. Use this if you need a different
166
+ # location for your state file.
167
+ #
168
+ # Set to false if your system cannot use a state file (e.g. many shared
169
+ # hosts).
166
170
  def self.state_file=(path)
167
171
  @state_file = path
168
172
  end
@@ -190,15 +194,18 @@ class UUID
190
194
  @last_clock = (Time.now.to_f * CLOCK_MULTIPLIER).to_i
191
195
  @mutex = Mutex.new
192
196
 
193
- if File.exist?(self.class.state_file) then
197
+ state_file = self.class.state_file
198
+ if state_file && File.size?(state_file) then
194
199
  next_sequence
195
200
  else
196
201
  @mac = Mac.addr.gsub(/:|-/, '').hex & 0x7FFFFFFFFFFF
197
202
  fail "Cannot determine MAC address from any available interface, tried with #{Mac.addr}" if @mac == 0
198
203
  @sequence = rand 0x10000
199
204
 
200
- open_lock 'w' do |io|
201
- write_state io
205
+ if state_file
206
+ open_lock 'w' do |io|
207
+ write_state io
208
+ end
202
209
  end
203
210
  end
204
211
  end
@@ -265,15 +272,19 @@ class UUID
265
272
  ##
266
273
  # Updates the state file with a new sequence number.
267
274
  def next_sequence
268
- open_lock 'r+' do |io|
269
- @mac, @sequence, @last_clock = read_state(io)
275
+ if self.class.state_file
276
+ open_lock 'r+' do |io|
277
+ @mac, @sequence, @last_clock = read_state(io)
270
278
 
271
- io.rewind
272
- io.truncate 0
279
+ io.rewind
280
+ io.truncate 0
273
281
 
274
- @sequence += 1
282
+ @sequence += 1
275
283
 
276
- write_state io
284
+ write_state io
285
+ end
286
+ else
287
+ @sequence += 1
277
288
  end
278
289
  rescue Errno::ENOENT
279
290
  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))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gn0m30-uuid
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Assaf Arkin