uuidtools 1.0.3 → 1.0.4

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.
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2005-2008 Robert Aman
2
+ # UUIDTools, Copyright (c) 2005-2008 Bob Aman
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -22,10 +22,10 @@
22
22
  #++
23
23
 
24
24
  class UUID
25
- module UUID_TOOLS_VERSION #:nodoc:
25
+ module VERSION #:nodoc:
26
26
  MAJOR = 1
27
27
  MINOR = 0
28
- TINY = 3
28
+ TINY = 4
29
29
 
30
30
  STRING = [MAJOR, MINOR, TINY].join('.')
31
31
  end
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,7 @@
1
+ spec_dir = File.expand_path(File.dirname(__FILE__))
2
+ lib_dir = File.expand_path(File.join(spec_dir, "../lib"))
3
+
4
+ $:.unshift(lib_dir)
5
+ $:.uniq!
6
+
7
+ require "uuidtools"
@@ -0,0 +1,15 @@
1
+ require File.join(File.dirname(__FILE__), "../spec_helper.rb")
2
+
3
+ describe UUID, "when obtaining a MAC address" do
4
+ before do
5
+ @mac_address = UUID.mac_address
6
+ end
7
+
8
+ it "should obtain a MAC address" do
9
+ @mac_address.should_not be_nil
10
+ end
11
+
12
+ it "should cache the MAC address" do
13
+ @mac_address.object_id.should == UUID.mac_address.object_id
14
+ end
15
+ end
@@ -0,0 +1,37 @@
1
+ require File.join(File.dirname(__FILE__), "../spec_helper.rb")
2
+
3
+ describe UUID, "when generating" do
4
+ it "should correctly generate SHA1 variant UUIDs" do
5
+ UUID.sha1_create(
6
+ UUID_URL_NAMESPACE, 'http://sporkmonger.com'
7
+ ).to_s.should == "f2d04685-b787-55da-8644-9bd28a6f5a53"
8
+ end
9
+
10
+ it "should correctly generate MD5 variant UUIDs" do
11
+ UUID.md5_create(
12
+ UUID_URL_NAMESPACE, 'http://sporkmonger.com'
13
+ ).to_s.should == "15074785-9071-3fe3-89bd-876e4b9e919b"
14
+ end
15
+
16
+ it "should correctly generate timestamp variant UUIDs" do
17
+ UUID.timestamp_create.to_s.should_not == UUID.timestamp_create.to_s
18
+ current_time = Time.now
19
+ UUID.timestamp_create(current_time).to_s.should_not ==
20
+ UUID.timestamp_create(current_time).to_s
21
+ uuids = []
22
+ 1000.times do
23
+ uuids << UUID.timestamp_create
24
+ end
25
+ # Check to make sure that none of the 10,000 UUIDs were duplicates
26
+ (uuids.map {|x| x.to_s}).uniq.size.should == uuids.size
27
+ end
28
+
29
+ it "should correctly generate random number variant UUIDs" do
30
+ uuids = []
31
+ 1000.times do
32
+ uuids << UUID.random_create
33
+ end
34
+ # Check to make sure that none of the 10,000 UUIDs were duplicates
35
+ (uuids.map {|x| x.to_s}).uniq.size.should == uuids.size
36
+ end
37
+ end
@@ -0,0 +1,36 @@
1
+ require File.join(File.dirname(__FILE__), "../spec_helper.rb")
2
+
3
+ describe UUID, "when parsing" do
4
+ it "should correctly parse the MAC address from a timestamp version UUID" do
5
+ UUID.timestamp_create.mac_address.should == UUID.mac_address
6
+ end
7
+
8
+ it "should correctly parse the variant from a timestamp version UUID" do
9
+ UUID.timestamp_create.variant.should == 0b100
10
+ end
11
+
12
+ it "should correctly parse the version from a timestamp version UUID" do
13
+ UUID.timestamp_create.version.should == 1
14
+ end
15
+
16
+ it "should correctly parse the timestamp from a timestamp version UUID" do
17
+ UUID.timestamp_create.timestamp.should < Time.now + 1
18
+ UUID.timestamp_create.timestamp.should > Time.now - 1
19
+ end
20
+
21
+ it "should not treat a timestamp version UUID as a nil UUID" do
22
+ UUID.timestamp_create.should_not be_nil_uuid
23
+ end
24
+
25
+ it "should not treat a timestamp version UUID as a random node UUID" do
26
+ UUID.timestamp_create.should_not be_random_node_id
27
+ end
28
+
29
+ it "should treat a timestamp version UUID as a random node UUID " +
30
+ "if there is no MAC address" do
31
+ old_mac_address = UUID.mac_address
32
+ UUID.mac_address = nil
33
+ UUID.timestamp_create.should be_random_node_id
34
+ UUID.mac_address = old_mac_address
35
+ end
36
+ end
@@ -0,0 +1,38 @@
1
+ task :benchmark do
2
+ require 'lib/uuidtools'
3
+ require 'benchmark'
4
+
5
+ # Version 1
6
+ result = Benchmark.measure do
7
+ 10000.times do
8
+ UUID.timestamp_create.to_s
9
+ end
10
+ end
11
+ puts "#{(10000.0 / result.real)} version 1 per second."
12
+
13
+ # Version 3
14
+ result = Benchmark.measure do
15
+ 10000.times do
16
+ UUID.md5_create(UUID_URL_NAMESPACE,
17
+ "http://www.ietf.org/rfc/rfc4122.txt").to_s
18
+ end
19
+ end
20
+ puts "#{(10000.0 / result.real)} version 3 per second."
21
+
22
+ # Version 4
23
+ result = Benchmark.measure do
24
+ 10000.times do
25
+ UUID.random_create.to_s
26
+ end
27
+ end
28
+ puts "#{(10000.0 / result.real)} version 4 per second."
29
+
30
+ # Version 5
31
+ result = Benchmark.measure do
32
+ 10000.times do
33
+ UUID.sha1_create(UUID_URL_NAMESPACE,
34
+ "http://www.ietf.org/rfc/rfc4122.txt").to_s
35
+ end
36
+ end
37
+ puts "#{(10000.0 / result.real)} version 5 per second."
38
+ end
@@ -0,0 +1,2 @@
1
+ desc "Remove all build products"
2
+ task "clobber"
@@ -0,0 +1,62 @@
1
+ require "rake/gempackagetask"
2
+
3
+ namespace :gem do
4
+ GEM_SPEC = Gem::Specification.new do |s|
5
+ s.name = PKG_NAME
6
+ s.version = PKG_VERSION
7
+ s.summary = PKG_SUMMARY
8
+ s.description = PKG_DESCRIPTION
9
+
10
+ s.files = PKG_FILES.to_a
11
+
12
+ s.has_rdoc = true
13
+ s.extra_rdoc_files = %w( README )
14
+ s.rdoc_options.concat ["--main", "README"]
15
+
16
+ s.add_dependency("rake", ">= 0.7.3")
17
+ s.add_dependency("rspec", ">= 1.0.8")
18
+
19
+ s.require_path = "lib"
20
+
21
+ s.author = "Bob Aman"
22
+ s.email = "bob@sporkmonger.com"
23
+ s.homepage = "http://#{PKG_NAME}.rubyforge.org/"
24
+ s.rubyforge_project = RUBY_FORGE_PROJECT
25
+ end
26
+
27
+ Rake::GemPackageTask.new(GEM_SPEC) do |p|
28
+ p.gem_spec = GEM_SPEC
29
+ p.need_tar = true
30
+ p.need_zip = true
31
+ end
32
+
33
+ desc "Show information about the gem"
34
+ task :debug do
35
+ puts GEM_SPEC.to_ruby
36
+ end
37
+
38
+ desc "Install the gem"
39
+ task :install => ["clobber", "gem:package"] do
40
+ sh "#{SUDO} gem install --local pkg/#{GEM_SPEC.full_name}"
41
+ end
42
+
43
+ desc "Uninstall the gem"
44
+ task :uninstall do
45
+ installed_list = Gem.source_index.find_name(PKG_NAME)
46
+ if installed_list &&
47
+ (installed_list.collect { |s| s.version.to_s}.include?(PKG_VERSION))
48
+ sh(
49
+ "#{SUDO} gem uninstall --version '#{PKG_VERSION}' " +
50
+ "--ignore-dependencies --executables #{PKG_NAME}"
51
+ )
52
+ end
53
+ end
54
+
55
+ desc "Reinstall the gem"
56
+ task :reinstall => [:uninstall, :install]
57
+ end
58
+
59
+ desc "Alias to gem:package"
60
+ task "gem" => "gem:package"
61
+
62
+ task "clobber" => ["gem:clobber_package"]
@@ -0,0 +1,40 @@
1
+ namespace :git do
2
+ namespace :tag do
3
+ desc "List tags from the Git repository"
4
+ task :list do
5
+ tags = `git tag -l`
6
+ tags.gsub!("\r", "")
7
+ tags = tags.split("\n").sort {|a, b| b <=> a }
8
+ puts tags.join("\n")
9
+ end
10
+
11
+ desc "Create a new tag in the Git repository"
12
+ task :create do
13
+ changelog = File.open("CHANGELOG", "r") { |file| file.read }
14
+ puts "-" * 80
15
+ puts changelog
16
+ puts "-" * 80
17
+ puts
18
+
19
+ v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
20
+ abort "Versions don't match #{v} vs #{PKG_VERSION}" if v != PKG_VERSION
21
+
22
+ tag = "#{PKG_NAME}-#{PKG_VERSION}"
23
+ msg = "Release #{PKG_NAME}-#{PKG_VERSION}"
24
+
25
+ existing_tags = `git tag -l #{PKG_NAME}-*`.split("\n")
26
+ if existing_tags.include?(tag)
27
+ warn("Tag already exists, deleting...")
28
+ unless system "git tag -d #{tag}"
29
+ abort "Tag deletion failed."
30
+ end
31
+ end
32
+ puts "Creating git tag '#{tag}'..."
33
+ unless system "git tag -a -m \"#{msg}\" #{tag}"
34
+ abort "Tag creation failed."
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ task "gem:release" => "git:tag:create"
@@ -0,0 +1,22 @@
1
+ namespace :metrics do
2
+ task :lines do
3
+ lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
4
+ for file_name in FileList["lib/**/*.rb"]
5
+ f = File.open(file_name)
6
+ while line = f.gets
7
+ lines += 1
8
+ next if line =~ /^\s*$/
9
+ next if line =~ /^\s*#/
10
+ codelines += 1
11
+ end
12
+ puts "L: #{sprintf("%4d", lines)}, " +
13
+ "LOC #{sprintf("%4d", codelines)} | #{file_name}"
14
+ total_lines += lines
15
+ total_codelines += codelines
16
+
17
+ lines, codelines = 0, 0
18
+ end
19
+
20
+ puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ require "rake/rdoctask"
2
+
3
+ namespace :doc do
4
+ desc "Generate RDoc documentation"
5
+ Rake::RDocTask.new do |rdoc|
6
+ rdoc.rdoc_dir = "doc"
7
+ rdoc.title = "#{PKG_NAME}-#{PKG_VERSION} Documentation"
8
+ rdoc.options << "--line-numbers" << "--inline-source" <<
9
+ "--accessor" << "cattr_accessor=object" << "--charset" << "utf-8"
10
+ rdoc.template = "#{ENV["template"]}.rb" if ENV["template"]
11
+ rdoc.rdoc_files.include("README", "CHANGELOG", "LICENSE")
12
+ rdoc.rdoc_files.include("lib/**/*.rb")
13
+ end
14
+
15
+ desc "Generate ri locally for testing"
16
+ task :ri do
17
+ sh "rdoc --ri -o ri ."
18
+ end
19
+
20
+ desc "Remove ri products"
21
+ task :clobber_ri do
22
+ rm_r "ri" rescue nil
23
+ end
24
+ end
25
+
26
+ desc "Alias to doc:rdoc"
27
+ task "doc" => "doc:rdoc"
28
+
29
+ task "clobber" => ["doc:clobber_rdoc", "doc:clobber_ri"]
@@ -0,0 +1,78 @@
1
+ require 'rubyforge'
2
+ require 'rake/contrib/sshpublisher'
3
+
4
+ namespace :gem do
5
+ desc 'Package and upload to RubyForge'
6
+ task :release => ["gem:package"] do |t|
7
+ v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
8
+ abort "Versions don't match #{v} vs #{PROJ.version}" if v != PKG_VERSION
9
+ pkg = "pkg/#{GEM_SPEC.full_name}"
10
+
11
+ rf = RubyForge.new
12
+ rf.configure
13
+ puts 'Logging in...'
14
+ rf.login
15
+
16
+ c = rf.userconfig
17
+ changelog = File.open("CHANGELOG") { |file| file.read }
18
+ c['release_changes'] = changelog
19
+ c['preformatted'] = true
20
+
21
+ files = ["#{pkg}.tgz", "#{pkg}.zip", "#{pkg}.gem"]
22
+
23
+ puts "Releasing #{PKG_NAME} v. #{PKG_VERSION}"
24
+ rf.add_release RUBY_FORGE_PROJECT, PKG_NAME, PKG_VERSION, *files
25
+ end
26
+ end
27
+
28
+ namespace :doc do
29
+ desc "Publish RDoc to RubyForge"
30
+ task :release => ["doc:rdoc"] do
31
+ config = YAML.load(
32
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
33
+ )
34
+ host = "#{config['username']}@rubyforge.org"
35
+ remote_dir = RUBY_FORGE_PATH + "/api"
36
+ local_dir = "doc"
37
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
38
+ end
39
+ end
40
+
41
+ namespace :spec do
42
+ desc "Publish specdoc to RubyForge"
43
+ task :release => ["spec:specdoc"] do
44
+ config = YAML.load(
45
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
46
+ )
47
+ host = "#{config['username']}@rubyforge.org"
48
+ remote_dir = RUBY_FORGE_PATH + "/specdoc"
49
+ local_dir = "specdoc"
50
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
51
+ end
52
+
53
+ namespace :rcov do
54
+ desc "Publish coverage report to RubyForge"
55
+ task :release => ["spec:rcov"] do
56
+ config = YAML.load(
57
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
58
+ )
59
+ host = "#{config['username']}@rubyforge.org"
60
+ remote_dir = RUBY_FORGE_PATH + "/coverage"
61
+ local_dir = "coverage"
62
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
63
+ end
64
+ end
65
+ end
66
+
67
+ namespace :website do
68
+ desc "Publish website to RubyForge"
69
+ task :release => ["doc:release", "spec:release", "spec:rcov:release"] do
70
+ config = YAML.load(
71
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
72
+ )
73
+ host = "#{config['username']}@rubyforge.org"
74
+ remote_dir = RUBY_FORGE_PATH
75
+ local_dir = "website"
76
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
77
+ end
78
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec/rake/verify_rcov'
2
+
3
+ namespace :spec do
4
+ Spec::Rake::SpecTask.new(:rcov) do |t|
5
+ t.spec_files = FileList['spec/**/*_spec.rb']
6
+ t.spec_opts = ['--color', '--format', 'specdoc']
7
+ t.rcov = true
8
+ t.rcov_opts = [
9
+ '--exclude', 'spec',
10
+ '--exclude', '1\\.8\\/gems',
11
+ '--exclude', '1\\.9\\/gems'
12
+ ]
13
+ end
14
+
15
+ RCov::VerifyTask.new(:verify) do |t|
16
+ t.threshold = 100.0
17
+ t.index_html = 'coverage/index.html'
18
+ end
19
+
20
+ task :verify => :rcov
21
+
22
+ desc "Generate HTML Specdocs for all specs"
23
+ Spec::Rake::SpecTask.new(:specdoc) do |t|
24
+ specdoc_path = File.expand_path(
25
+ File.join(File.dirname(__FILE__), '../specdoc/'))
26
+ Dir.mkdir(specdoc_path) if !File.exist?(specdoc_path)
27
+
28
+ output_file = File.join(specdoc_path, 'index.html')
29
+ t.spec_files = FileList['spec/**/*_spec.rb']
30
+ t.spec_opts = ["--format", "\"html:#{output_file}\"", "--diff"]
31
+ t.fail_on_error = false
32
+ end
33
+
34
+ namespace :rcov do
35
+ desc "Browse the code coverage report."
36
+ task :browse => "spec:rcov" do
37
+ Rake.browse("coverage/index.html")
38
+ end
39
+ end
40
+ end
41
+
42
+ desc "Alias to spec:verify"
43
+ task "spec" => "spec:verify"
44
+
45
+ task "clobber" => ["spec:clobber_rcov"]
46
+
47
+ module Rake
48
+ def self.browse(filepath)
49
+ if RUBY_PLATFORM =~ /mswin/
50
+ system(filepath)
51
+ else
52
+ try_browsers = lambda do
53
+ result = true
54
+ if !(`which firefox 2>&1` =~ /no firefox/)
55
+ system("firefox #{filepath}")
56
+ elsif !(`which mozilla 2>&1` =~ /no mozilla/)
57
+ system("mozilla #{filepath}")
58
+ elsif !(`which netscape 2>&1` =~ /no netscape/)
59
+ system("netscape #{filepath}")
60
+ elsif !(`which links 2>&1` =~ /no links/)
61
+ system("links #{filepath}")
62
+ elsif !(`which lynx 2>&1` =~ /no lynx/)
63
+ system("lynx #{filepath}")
64
+ else
65
+ result = false
66
+ end
67
+ result
68
+ end
69
+ opened = false
70
+ if RUBY_PLATFORM =~ /darwin/
71
+ opened = true
72
+ system("open #{filepath}")
73
+ elsif !(`which gnome-open 2>&1` =~ /no gnome-open/)
74
+ success =
75
+ !(`gnome-open #{filepath} 2>&1` =~ /There is no default action/)
76
+ if !success
77
+ opened = try_browsers.call()
78
+ else
79
+ opened = true
80
+ end
81
+ else
82
+ opened = try_browsers.call()
83
+ end
84
+ if !opened
85
+ puts "Don't know how to browse to location."
86
+ end
87
+ end
88
+ end
89
+ end