uuidtools 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == UUIDTools 0.1.4
2
+ * improved speed when generating timestamp-based uuids
3
+ * fixed bug with rapid generation of timestamp uuids leading to dupicates
4
+ * improved code for detection of mac address
1
5
  == UUIDTools 0.1.3
2
6
  * fixed issue with UUID#raw attempting to call protected class methods
3
7
  == UUIDTools 0.1.2
data/lib/uuidtools.rb CHANGED
@@ -21,7 +21,7 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #++
23
23
 
24
- UUID_TOOLS_VERSION = "0.1.3"
24
+ UUID_TOOLS_VERSION = "0.1.4"
25
25
 
26
26
  $:.unshift(File.dirname(__FILE__))
27
27
 
@@ -103,6 +103,7 @@ require 'digest/md5'
103
103
  # UUID.random_create
104
104
  # => #<UUID:0x19013a UUID:984265dc-4200-4f02-ae70-fe4f48964159>
105
105
  class UUID
106
+ @@mac_address = nil
106
107
  @@last_timestamp = nil
107
108
  @@last_node_id = nil
108
109
  @@last_clock_sequence = nil
@@ -247,7 +248,7 @@ class UUID
247
248
  # The node id has changed. Change the clock id.
248
249
  clock_sequence = UUID.convert_byte_string_to_int(UUID.true_random)
249
250
  elsif @@last_timestamp != nil &&
250
- gmt_timestamp_100_nanoseconds < @@last_timestamp
251
+ gmt_timestamp_100_nanoseconds <= @@last_timestamp
251
252
  clock_sequence = clock_sequence + 1
252
253
  end
253
254
  @@last_timestamp = gmt_timestamp_100_nanoseconds
@@ -460,42 +461,45 @@ class UUID
460
461
  # Returns the MAC address of the current computer's network card.
461
462
  # Returns nil if a MAC address could not be found.
462
463
  def UUID.get_mac_address #:nodoc:
463
- if RUBY_PLATFORM =~ /win/ && !(RUBY_PLATFORM =~ /darwin/)
464
- begin
465
- ifconfig_output = `ipconfig /all`
466
- mac_addresses = ifconfig_output.scan(
467
- Regexp.new("(#{(["[0-9A-F]{2}"] * 6).join("-")})"))
468
- if mac_addresses.size > 0
469
- return mac_addresses.first.first.downcase.gsub(/-/, ":")
470
- end
471
- rescue
472
- end
473
- else
474
- begin
475
- ifconfig_output = `ifconfig`
476
- mac_addresses = ifconfig_output.scan(
477
- Regexp.new("ether (#{(["[0-9a-f]{2}"] * 6).join(":")})"))
478
- if mac_addresses.size == 0
479
- ifconfig_output = `ifconfig | grep HWaddr | cut -c39-`
464
+ if @@mac_address.nil?
465
+ if RUBY_PLATFORM =~ /win/ && !(RUBY_PLATFORM =~ /darwin/)
466
+ begin
467
+ ifconfig_output = `ipconfig /all`
480
468
  mac_addresses = ifconfig_output.scan(
481
- Regexp.new("(#{(["[0-9a-f]{2}"] * 6).join(":")})"))
469
+ Regexp.new("(#{(["[0-9a-fA-F]{2}"] * 6).join("-")})"))
470
+ if mac_addresses.size > 0
471
+ @@mac_address = mac_addresses.first.first.downcase.gsub(/-/, ":")
472
+ end
473
+ rescue
482
474
  end
483
- if mac_addresses.size == 0
484
- ifconfig_output = `/sbin/ifconfig`
485
- mac_addresses = ifconfig_output.scan(
486
- Regexp.new("ether (#{(["[0-9a-f]{2}"] * 6).join(":")})"))
487
- end
488
- if mac_addresses.size == 0
489
- ifconfig_output = `/sbin/ifconfig | grep HWaddr | cut -c39-`
475
+ else
476
+ begin
477
+ ifconfig_output = `ifconfig`
490
478
  mac_addresses = ifconfig_output.scan(
491
- Regexp.new("(#{(["[0-9a-f]{2}"] * 6).join(":")})"))
479
+ Regexp.new("ether (#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"))
480
+ if mac_addresses.size == 0
481
+ ifconfig_output = `ifconfig | grep HWaddr | cut -c39-`
482
+ mac_addresses = ifconfig_output.scan(
483
+ Regexp.new("(#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"))
484
+ end
485
+ if mac_addresses.size == 0
486
+ ifconfig_output = `/sbin/ifconfig`
487
+ mac_addresses = ifconfig_output.scan(
488
+ Regexp.new("ether (#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"))
489
+ end
490
+ if mac_addresses.size == 0
491
+ ifconfig_output = `/sbin/ifconfig | grep HWaddr | cut -c39-`
492
+ mac_addresses = ifconfig_output.scan(
493
+ Regexp.new("(#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"))
494
+ end
495
+ if mac_addresses.size > 0
496
+ @@mac_address = mac_addresses.first.first
497
+ end
498
+ rescue
492
499
  end
493
- if mac_addresses.size > 0
494
- return mac_addresses.first.first
495
- end
496
- rescue
497
500
  end
498
501
  end
502
+ return @@mac_address
499
503
  end
500
504
 
501
505
  # Returns 128 bits of highly unpredictable data.
data/rakefile CHANGED
@@ -7,7 +7,7 @@ require 'rake/gempackagetask'
7
7
  require 'rake/contrib/rubyforgepublisher'
8
8
 
9
9
  PKG_NAME = 'uuidtools'
10
- PKG_VERSION = '0.1.3'
10
+ PKG_VERSION = '0.1.4'
11
11
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
12
12
 
13
13
  RELEASE_NAME = "REL #{PKG_VERSION}"
data/test/create_test.rb CHANGED
@@ -22,9 +22,15 @@ class CreateTest < Test::Unit::TestCase
22
22
  UUID.timestamp_create.to_s,
23
23
  UUID.timestamp_create.to_s)
24
24
  current_time = Time.now
25
- assert_equal(
25
+ assert_not_equal(
26
26
  UUID.timestamp_create(current_time).to_s,
27
27
  UUID.timestamp_create(current_time).to_s)
28
+ uuids = []
29
+ 1000.times do
30
+ uuids << UUID.timestamp_create
31
+ end
32
+ assert_equal(uuids.size, (uuids.map {|x| x.to_s}).uniq.size,
33
+ "Duplicate timestamp-based UUID generated.")
28
34
  end
29
35
 
30
36
  def test_random_create
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: uuidtools
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.3
7
- date: 2005-09-28 00:00:00 -04:00
6
+ version: 0.1.4
7
+ date: 2005-11-11 00:00:00 -05:00
8
8
  summary: Generation of UUIDs.
9
9
  require_paths:
10
10
  - lib