uuid 1.0.2 → 1.0.3
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 +5 -0
- data/lib/uuid.rb +18 -16
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
Release 1.0.3 (Nov 8, 2006)
|
2
|
+
|
3
|
+
* Fixed: Work around YAML bug in serializing that occurs when MAC address
|
4
|
+
consists only of decimal digits. Credit: ebuprofen"
|
5
|
+
|
1
6
|
Release 1.0.2 (Jul 28, 2006)
|
2
7
|
|
3
8
|
* Changed: Constants are not conditionally defined (removes warnings when
|
data/lib/uuid.rb
CHANGED
@@ -113,7 +113,7 @@ require 'logger'
|
|
113
113
|
module UUID
|
114
114
|
|
115
115
|
unless const_defined?(:VERSION)
|
116
|
-
VERSION = '1.0.
|
116
|
+
VERSION = '1.0.3'
|
117
117
|
|
118
118
|
PACKAGE = "uuid"
|
119
119
|
|
@@ -179,7 +179,7 @@ module UUID
|
|
179
179
|
# :call-seq:
|
180
180
|
# UUID.new([format]) -> string
|
181
181
|
#
|
182
|
-
def new
|
182
|
+
def new(format = nil)
|
183
183
|
# Determine which format we're using for the UUID string.
|
184
184
|
template = FORMATS[format || :default] or
|
185
185
|
raise RuntimeError, "I don't know the format '#{format}'"
|
@@ -240,7 +240,7 @@ module UUID
|
|
240
240
|
# :call-seq:
|
241
241
|
# UUID.config(config)
|
242
242
|
#
|
243
|
-
def self.config
|
243
|
+
def self.config(options)
|
244
244
|
options ||= {}
|
245
245
|
@@mutex.synchronize do
|
246
246
|
@@logger = options[:logger]
|
@@ -252,7 +252,7 @@ module UUID
|
|
252
252
|
# Create a uuid.state file by finding the IEEE 802 NIC MAC address for this machine.
|
253
253
|
# Works for UNIX (ifconfig) and Windows (ipconfig). Creates the uuid.state file in the
|
254
254
|
# installation directory (typically the GEM's lib).
|
255
|
-
def self.setup
|
255
|
+
def self.setup()
|
256
256
|
file = File.expand_path(File.dirname(__FILE__))
|
257
257
|
file = File.basename(file) == 'lib' ? file = File.join(file, '..', STATE_FILE) : file = File.join(file, STATE_FILE)
|
258
258
|
file = File.expand_path(file)
|
@@ -278,7 +278,7 @@ module UUID
|
|
278
278
|
addresses.each { |addr| puts " #{addr}" }
|
279
279
|
puts "Selecting the first address #{addresses[0]} for use in your UUID state file."
|
280
280
|
File.open file, "w" do |output|
|
281
|
-
output.puts "mac_addr: #{addresses[0]}"
|
281
|
+
output.puts "mac_addr: \"#{addresses[0]}\""
|
282
282
|
output.puts format("sequence: \"0x%04x\"", rand(0x10000))
|
283
283
|
end
|
284
284
|
puts "Created a new UUID state file: #{file}"
|
@@ -289,15 +289,8 @@ module UUID
|
|
289
289
|
|
290
290
|
|
291
291
|
private
|
292
|
-
def self.state plus_one = false
|
293
|
-
return nil unless @@sequence && @@mac_addr
|
294
|
-
{ "sequence"=>sprintf("0x%04x", (plus_one ? @@sequence + 1 : @@sequence) & 0xFFFF),
|
295
|
-
"last_clock"=>sprintf("0x%x", @@last_clock || (Time.new.to_f * CLOCK_MULTIPLIER).to_i),
|
296
|
-
"mac_addr" => @@mac_addr }
|
297
|
-
end
|
298
|
-
|
299
292
|
|
300
|
-
def self.next_sequence
|
293
|
+
def self.next_sequence(config = nil)
|
301
294
|
# If called to advance the sequence number (config is nil), we have a state file that we're able to use.
|
302
295
|
# If called from configuration, use the specified or default state file.
|
303
296
|
state_file = (config && config[:state_file]) || @@state_file
|
@@ -338,7 +331,7 @@ private
|
|
338
331
|
# the new state. Start at beginning of file, and truncate file when done.
|
339
332
|
@@mac_addr, @@mac_hex, @@sequence, @@state_file = mac_addr, mac_hex, sequence, state_file
|
340
333
|
file.pos = 0
|
341
|
-
|
334
|
+
dump file, true
|
342
335
|
file.truncate file.pos
|
343
336
|
end
|
344
337
|
# Initialized.
|
@@ -375,7 +368,7 @@ private
|
|
375
368
|
file.flock(File::LOCK_EX)
|
376
369
|
@@mac_addr, @@mac_hex, @@sequence, @@state_file = mac_addr, mac_hex, sequence, state_file
|
377
370
|
file.pos = 0
|
378
|
-
|
371
|
+
dump file, true
|
379
372
|
file.truncate file.pos
|
380
373
|
end
|
381
374
|
# Initialized.
|
@@ -392,13 +385,22 @@ private
|
|
392
385
|
end
|
393
386
|
end
|
394
387
|
|
388
|
+
def self.dump(file, plus_one)
|
389
|
+
# Gets around YAML weirdness, like ont storing the MAC address as a string.
|
390
|
+
if @@sequence && @@mac_addr
|
391
|
+
file.puts "mac_addr: \"#{@@mac_addr}\""
|
392
|
+
file.puts "sequence: \"0x%04x\"" % ((plus_one ? @@sequence + 1 : @@sequence) & 0xFFFF)
|
393
|
+
file.puts "last_clock: \"0x%x\"" % (@@last_clock || (Time.new.to_f * CLOCK_MULTIPLIER).to_i)
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
395
397
|
end
|
396
398
|
|
397
399
|
|
398
400
|
if defined?(ActiveRecord)
|
399
401
|
class ActiveRecord::Base
|
400
402
|
|
401
|
-
def self.uuid_primary_key
|
403
|
+
def self.uuid_primary_key()
|
402
404
|
before_create { |record| record.id = UUID.new unless record.id }
|
403
405
|
end
|
404
406
|
|
metadata
CHANGED