Imported Upstream version 2.3.7

parents
2.3.7 (2013-02-18)
Use Dir.tmpdir instead of hardcoded /var/tmp path (Justin Langhorst).
2.3.6 (2012-11-18)
Manually setting the state_file path sets mode too (Tom Lea).
When manually setting the state file, set the mode too. Failure to do so
causes an implicit conversion of nil to integer on first usage.
Also provided a mode method to set the mode explicitly.
Reverted executable loss (Michael Witrant ).
2.3.4 (2012-01-23)
Source files are now UTF-8 (Vicente Reig)
2.3.4 (2011-09-01)
Fixed State file mode isn't respected with standard umask (Brandon Turner).
2.3.3 (2011-08-01)
Check if ruby-uuid is writable: it might have been claimed by another user on
the system already (Andy Lo-A-Foe)
2.3.2 (2011-04-11)
* Allow usage on environments that don't have MAC address accessible (mikezter)
* Fix for JRuby expand_path interpretation on windows (pinnymz)
2.3.1 (2010-05-07)
* Fix: Open state file in binary mode (http://github.com/assaf/uuid/issues#issue/8)
2.3.0 (2010-04-07)
* Added: UUID.generator returns the current UUID generator. Particularly useful for calling
next_sequence on the generator when forking a process.
* Added: UUID::Server and UUID::Client so you can have one process serving you UUIDs.
* Added: UUID command line tool. Yay!
2.2.0 (2010-02-18)
* Added: set UUID.state_file = false if you cannot use a state file (e.g. shared hosting environment)
2.1.1 (2010-01-27)
* Fixed bug which caused UUID.new to fail if the state file was somehow extant but empty
2.1.0 (2009-12-16)
* Added uuid.validate -- easier to implement than explain why it's wrong.
2.0.2 (2009-06-10)
* Maintenance release. Added uuid.gemspec file in packaging, tested against
Ruby 1.9.1.
2.0.1 (2008-08-28)
* Fixed: MAC address parses correctly when using colon as separator, not
when using hyphen (ruby-mingw32). If your MAC address is all zero
(check with UUID.new.inspect), remove the ruby-uuid file, and it
will reset to the actual MAC address. (Rasha)
* Fixed: UUID.new.inspect not showing full MAC address.
2.0.0 (2008-08-28)
* Changed: API. UUID.generate still works as it always did, but the rest of
the API is brand spanking new, so if you rely on anything besides
UUID.generate, or just curious, check out the rdocs.
* Changed: uuid.state replaced by ruby-uuid file. By default stored in
/var/tmp, or if that path is not accessible, as .ruby-uuid in the
home directory.
* Changed: ruby-uuid is now stored as binary file (faster read/write), if you
need to have a peek, open irb and type UUID.new.inspect.
* Changed: Source code and documentation for this release hosted on the
wonderful Github: http://github.com/assaf/uuid
1.0.4 (2007-08-28)
* Changed: By default creates the uuid.state file in the working directory,
not in the installation directory, which requires sudo privileges
(e.g. gem).
1.0.3 (2006-11-08)
* Fixed: Work around YAML bug in serializing that occurs when MAC address
consists only of decimal digits. Credit: ebuprofen"
1.0.2 (2006-08-19)
* Changed: Constants are not conditionally defined (removes warnings when
using in Rails.
1.0.1 (2006-07-27)
* Added: Regular expressions to test if a string is a UUID.
* Changed: When used in ActiveRecord, adds as callback instead of overriding
save.
1.0.0 (2005-11-20)
* Changed: Separated form reliable-msg into its own package.
Copyright (c) 2005-2012 Assaf Arkin, Eric Hodel
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
= UUID Generator
Generates universally unique identifiers (UUIDs) for use in distributed
applications. Based on {RFC 4122}[http://www.ietf.org/rfc/rfc4122.txt].
== Generating UUIDs
Call #generate to generate a new UUID. The method returns a string in one of
three formats. The default format is 36 characters long, and contains the 32
hexadecimal octets and hyphens separating the various value parts. The
<tt>:compact</tt> format omits the hyphens, while the <tt>:urn</tt> format
adds the <tt>:urn:uuid</tt> prefix.
For example:
uuid = UUID.new
10.times do
p uuid.generate
end
== UUIDs in Brief
UUID (universally unique identifier) are guaranteed to be unique across time
and space.
A UUID is 128 bit long, and consists of a 60-bit time value, a 16-bit
sequence number and a 48-bit node identifier.
The time value is taken from the system clock, and is monotonically
incrementing. However, since it is possible to set the system clock
backward, a sequence number is added. The sequence number is incremented
each time the UUID generator is started. The combination guarantees that
identifiers created on the same machine are unique with a high degree of
probability.
Note that due to the structure of the UUID and the use of sequence number,
there is no guarantee that UUID values themselves are monotonically
incrementing. The UUID value cannot itself be used to sort based on order
of creation.
To guarantee that UUIDs are unique across all machines in the network,
the IEEE 802 MAC address of the machine's network interface card is used as
the node identifier.
For more information see {RFC 4122}[http://www.ietf.org/rfc/rfc4122.txt].
== UUID State File
The UUID generator uses a state file to hold the MAC address and sequence
number.
The MAC address is used to generate identifiers that are unique to your
machine, preventing conflicts in distributed applications. The MAC
address is six bytes (48 bit) long. It is automatically extracted from
one of the network cards on your machine.
The sequence number is incremented each time the UUID generator is
first used by the application, to prevent multiple processes from
generating the same set of identifiers, and deal with changes to the
system clock.
The UUID state file is created in <tt>#Dir.tmpdir/ruby-uuid</tt> or the Windows
common application data directory using mode 0644. If that directory is not
writable, the file is created as <tt>.ruby-uuid</tt> in the home directory.
If you need to create the file with a different mode, use UUID#state_file
before running the UUID generator.
Note: If you are running on a shared host where the state file is not shared
between processes, or persisted across restarts (e.g. Heroku, Google App
Engine) you can simple turn it off:
UUID.state_file = false
State files are not portable across machines.
If you do not use the state file, UUID generation will attempt to use your
server's MAC address using the macaddr gem, which runs system commands to
identify the MAC address and then cache it. Since this can take a few seconds
on some operating systems, when using UUID.state_file = false, you should add
the following line after disabling the state file:
UUID.generator.next_sequence
Note: when using a forking server (Unicorn, Resque, Pipemaster, etc) you don't
want your forked processes using the same sequence number. Make sure to
increment the sequence number each time a worker forks.
For example, in config/unicorn.rb:
after_fork do |server, worker|
UUID.generator.next_sequence
end
== Command Line
You can run uuid from the command line, generating new UUID to stdout:
$ uuid
Multiple UUIDs in a sequence, separated with a newline:
$ uuid --count 10
You can also run client and server from the command line
$ uuid --server &
$ uuid --socket /var/lib/uuid.sock
== Latest and Greatest
Source code and documentation hosted on Github: http://github.com/assaf/uuid
To get UUID from source:
git clone git://github.com/assaf/uuid.git
== License
This package is licensed under the MIT license and/or the Creative
Commons Attribution-ShareAlike.
:include: MIT-LICENSE
require 'rake/testtask'
#require 'rake/rdoctask'
spec = Gem::Specification.load(File.expand_path("uuid.gemspec", File.dirname(__FILE__)))
desc "Default Task"
task :default => :test
desc "Run all test cases"
Rake::TestTask.new do |test|
test.verbose = true
test.test_files = ['test/*.rb']
test.warning = true
end
# Create the documentation.
#Rake::RDocTask.new do |rdoc|
# rdoc.rdoc_files.include "README.rdoc", "lib/**/*.rb"
# rdoc.options = spec.rdoc_options
#end
desc "Push new release to rubyforge and git tag"
task :push do
sh "git push"
puts "Tagging version #{spec.version} .."
sh "git tag v#{spec.version}"
sh "git push --tag"
puts "Building and pushing gem .."
sh "gem build #{spec.name}.gemspec"
sh "gem push #{spec.name}-#{spec.version}.gem"
end
desc "Install #{spec.name} locally"
task :install do
sh "gem build #{spec.name}.gemspec"
sh "gem install #{spec.name}-#{spec.version}.gem"
end
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'rake' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require 'rubygems'
require 'bundler/setup'
load Gem.bin_path('rake', 'rake')
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'uuid' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require 'rubygems'
require 'bundler/setup'
load Gem.bin_path('uuid', 'uuid')
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'yard' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require 'rubygems'
require 'bundler/setup'
load Gem.bin_path('yard', 'yard')
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'yardoc' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require 'rubygems'
require 'bundler/setup'
load Gem.bin_path('yard', 'yardoc')
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'yri' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require 'rubygems'
require 'bundler/setup'
load Gem.bin_path('yard', 'yri')
This diff is collapsed.
--- !ruby/object:Gem::Specification
name: uuid
version: !ruby/object:Gem::Version
version: 2.3.7
prerelease:
platform: ruby
authors:
- Assaf Arkin
- Eric Hodel
autorequire:
bindir: bin
cert_chain: []
date: 2013-02-18 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: macaddr
requirement: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.0'
type: :runtime
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '1.0'
description: ! 'UUID generator for producing universally unique identifiers based
on RFC 4122
(http://www.ietf.org/rfc/rfc4122.txt).
'
email: assaf@labnotes.org
executables:
- uuid
extensions: []
extra_rdoc_files:
- README.rdoc
- MIT-LICENSE
files:
- bin/rake
- bin/uuid
- bin/yard
- bin/yardoc
- bin/yri
- test/test-uuid.rb
- lib/uuid.rb
- README.rdoc
- MIT-LICENSE
- Rakefile
- CHANGELOG
- uuid.gemspec
homepage: http://github.com/assaf/uuid
licenses: []
post_install_message:
rdoc_options:
- --main
- README.rdoc
- --title
- UUID generator
- --line-numbers
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
required_rubygems_version: !ruby/object:Gem::Requirement
none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
requirements: []
rubyforge_project:
rubygems_version: 1.8.23
signing_key:
specification_version: 3
summary: UUID generator
test_files: []
# encoding: UTF-8
# Author:: Assaf Arkin assaf@labnotes.org
# Eric Hodel drbrain@segment7.net
# Copyright:: Copyright (c) 2005-2008 Assaf Arkin, Eric Hodel
# License:: MIT and/or Creative Commons Attribution-ShareAlike
require 'test/unit'
require 'rubygems'
require 'uuid'
require 'mocha'
class TestUUID < Test::Unit::TestCase
def test_state_file_creation
path = UUID.state_file
File.delete path if File.exist?(path)
UUID.new.generate
File.exist?(path)
end
def test_state_file_creation_mode
UUID.class_eval{ @state_file = nil; @mode = nil }
UUID.state_file 0666
path = UUID.state_file
File.delete path if File.exist?(path)
old_umask = File.umask(0022)
UUID.new.generate
File.umask(old_umask)
assert_equal '0666', sprintf('%04o', File.stat(path).mode & 0777)
end
def test_state_file_specify
path = File.join("path", "to", "ruby-uuid")
UUID.state_file = path
assert_equal path, UUID.state_file
end
def test_mode_is_set_on_state_file_specify
UUID.class_eval{ @state_file = nil; @mode = nil }
path = File.join(Dir.tmpdir, "ruby-uuid-test")
File.delete path if File.exist?(path)
UUID.state_file = path
old_umask = File.umask(0022)
UUID.new.generate
File.umask(old_umask)
UUID.class_eval{ @state_file = nil; @mode = nil }
assert_equal '0644', sprintf('%04o', File.stat(path).mode & 0777)
end
def test_with_no_state_file
UUID.state_file = false
assert !UUID.state_file
uuid = UUID.new
assert_match(/\A[\da-f]{32}\z/i, uuid.generate(:compact))
seq = uuid.next_sequence
assert_equal seq + 1, uuid.next_sequence
assert !UUID.state_file
end
def validate_uuid_generator(uuid)
assert_match(/\A[\da-f]{32}\z/i, uuid.generate(:compact))
assert_match(/\A[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}\z/i,
uuid.generate(:default))
assert_match(/^urn:uuid:[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}\z/i,
uuid.generate(:urn))
e = assert_raise ArgumentError do
uuid.generate :unknown
end
assert_equal 'invalid UUID format :unknown', e.message
end
def test_instance_generate
uuid = UUID.new
validate_uuid_generator(uuid)
end
def test_class_generate
assert_match(/\A[\da-f]{32}\z/i, UUID.generate(:compact))
assert_match(/\A[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}\z/i,
UUID.generate(:default))
assert_match(/^urn:uuid:[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}\z/i,
UUID.generate(:urn))
e = assert_raise ArgumentError do
UUID.generate :unknown
end
assert_equal 'invalid UUID format :unknown', e.message
end
def test_class_validate
assert !UUID.validate('')
assert UUID.validate('01234567abcd8901efab234567890123'), 'compact'
assert UUID.validate('01234567-abcd-8901-efab-234567890123'), 'default'
assert UUID.validate('urn:uuid:01234567-abcd-8901-efab-234567890123'),
'urn'
assert UUID.validate('01234567ABCD8901EFAB234567890123'), 'compact'
assert UUID.validate('01234567-ABCD-8901-EFAB-234567890123'), 'default'
assert UUID.validate('urn:uuid:01234567-ABCD-8901-EFAB-234567890123'),
'urn'
end
def test_monotonic
seen = {}
uuid_gen = UUID.new
20_000.times do
uuid = uuid_gen.generate
assert !seen.has_key?(uuid), "UUID repeated"
seen[uuid] = true
end
end
def test_same_mac
class << foo = UUID.new
attr_reader :mac
end
class << bar = UUID.new
attr_reader :mac
end
assert_equal foo.mac, bar.mac
end
def test_increasing_sequence
class << foo = UUID.new
attr_reader :sequence
end
class << bar = UUID.new
attr_reader :sequence
end
assert_equal foo.sequence + 1, bar.sequence
end
def test_pseudo_random_mac_address
uuid_gen = UUID.new
Mac.stubs(:addr).returns "00:00:00:00:00:00"
assert uuid_gen.iee_mac_address == 0
[:compact, :default, :urn].each do |format|
assert UUID.validate(uuid_gen.generate(format)), format.to_s
end
validate_uuid_generator(uuid_gen)
end
end
Gem::Specification.new do |s|
s.name = 'uuid'
s.version = '2.3.7'
s.summary = "UUID generator"
s.description = <<-EOF
UUID generator for producing universally unique identifiers based on RFC 4122
(http://www.ietf.org/rfc/rfc4122.txt).
EOF
s.authors << 'Assaf Arkin' << 'Eric Hodel'
s.email = 'assaf@labnotes.org'
s.homepage = 'http://github.com/assaf/uuid'
s.files = Dir['{bin,test,lib,docs}/**/*'] + ['README.rdoc', 'MIT-LICENSE', 'Rakefile', 'CHANGELOG', 'uuid.gemspec']
s.executables = "uuid"
s.rdoc_options << '--main' << 'README.rdoc' << '--title' << 'UUID generator' << '--line-numbers'
'--webcvs' << 'http://github.com/assaf/uuid'
s.extra_rdoc_files = ['README.rdoc', 'MIT-LICENSE']
s.add_dependency 'macaddr', ['~>1.0']
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment