usesguid 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/Gemfile +4 -0
- data/{LICENSE → LICENSE.txt} +3 -2
- data/README.rdoc +28 -13
- data/Rakefile +1 -49
- data/lib/usesguid.rb +3 -2
- data/lib/usesguid/active_record_extensions.rb +28 -21
- data/lib/usesguid/uuid22.rb +6 -3
- data/lib/usesguid/uuid_mysql.rb +9 -6
- data/lib/usesguid/uuid_sqlserver.rb +8 -0
- data/lib/usesguid/uuidtools.rb +76 -76
- data/lib/usesguid/version.rb +3 -0
- data/usesguid.gemspec +19 -54
- metadata +76 -55
- data/History.txt +0 -3
- data/VERSION +0 -1
data/.gitignore
ADDED
data/Gemfile
ADDED
data/{LICENSE → LICENSE.txt}
RENAMED
data/README.rdoc
CHANGED
@@ -23,13 +23,7 @@ This library is free software; you can redistribute it and/or modify it
|
|
23
23
|
under the terms of the MIT license.
|
24
24
|
|
25
25
|
|
26
|
-
==
|
27
|
-
|
28
|
-
sudo gem install usesguid
|
29
|
-
|
30
|
-
In Rails environment file:
|
31
|
-
|
32
|
-
config.gem "usesguid"
|
26
|
+
== USAGE
|
33
27
|
|
34
28
|
define ID as char(22)
|
35
29
|
call "usesguid" in ActiveRecord class declaration, like:
|
@@ -38,13 +32,34 @@ call "usesguid" in ActiveRecord class declaration, like:
|
|
38
32
|
usesguid
|
39
33
|
end
|
40
34
|
|
41
|
-
|
35
|
+
If your ID field is not called "ID", call "usesguid :column =>'IdColumnName'"
|
36
|
+
|
37
|
+
In order to use a GUID in another field that is not your primary key, id call usesguid like:
|
38
|
+
|
39
|
+
class Mymodel < ActiveRecord::Base
|
40
|
+
usesguid, :as => :field
|
41
|
+
end
|
42
|
+
|
43
|
+
If you would like to validate your GUID a validation macro is provided:
|
44
|
+
|
45
|
+
class Mymodel < ActiveRecord::Base
|
46
|
+
usesguid, :as => :field
|
47
|
+
|
48
|
+
validate_guid
|
49
|
+
end
|
50
|
+
|
51
|
+
validate_guid is the same as:
|
42
52
|
|
43
|
-
|
44
|
-
|
53
|
+
validates_presence_of( ActiveRecord::Base.guid_column )
|
54
|
+
validates_uniqueness_of( ActiveRecord::Base.guid_column )
|
55
|
+
validates_length_of( ActiveRecord::Base.guid_column, :maximum => (ActiveRecord::Base.guid_compression == 's22' ? 22 : 36), :allow_blank => true )
|
45
56
|
|
46
|
-
|
57
|
+
If you use MySQL or SQL Server as your database, you can make guid generation much faster by using the
|
58
|
+
database to generate GUIDs.
|
47
59
|
|
48
|
-
|
60
|
+
You can accomplish this by specifying the GUID generator in an initializer file. There are also options
|
61
|
+
for guid_compression and guid_column.
|
49
62
|
|
50
|
-
|
63
|
+
ActiveRecord::Base.guid_generator = :mysql # mysql or sqlserver
|
64
|
+
ActiveRecord::Base.guid_compression = :s # :s for string or :s22 for compressed string
|
65
|
+
ActiveRecord::Base.guid_column = 'guid' # the name of your GUID column
|
data/Rakefile
CHANGED
@@ -1,49 +1 @@
|
|
1
|
-
require
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "usesguid"
|
8
|
-
gem.summary = %Q{A much faster version of the usesguid plugin for Rails}
|
9
|
-
gem.description = %Q{A much faster version of the usesguid plugin for Rails (uses MySQL to generate GUIDs)}
|
10
|
-
gem.email = "jason@lookforwardenterprises.com"
|
11
|
-
gem.homepage = "http://github.com/midas/usesguid"
|
12
|
-
gem.authors = ["Brian Morearty","Demetrio Nunes","Robert Aman","C. Jason Harrelson(midas)"]
|
13
|
-
gem.add_development_dependency "rspec"
|
14
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
-
end
|
16
|
-
Jeweler::GemcutterTasks.new
|
17
|
-
rescue LoadError
|
18
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
-
end
|
20
|
-
|
21
|
-
require 'spec/rake/spectask'
|
22
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
-
spec.libs << 'lib' << 'spec'
|
24
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
-
end
|
26
|
-
|
27
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
-
spec.libs << 'lib' << 'spec'
|
29
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
-
spec.rcov = true
|
31
|
-
end
|
32
|
-
|
33
|
-
task :spec => :check_dependencies
|
34
|
-
|
35
|
-
task :default => :spec
|
36
|
-
|
37
|
-
require 'rake/rdoctask'
|
38
|
-
Rake::RDocTask.new do |rdoc|
|
39
|
-
if File.exist?('VERSION')
|
40
|
-
version = File.read('VERSION')
|
41
|
-
else
|
42
|
-
version = ""
|
43
|
-
end
|
44
|
-
|
45
|
-
rdoc.rdoc_dir = 'rdoc'
|
46
|
-
rdoc.title = "usesguid #{version}"
|
47
|
-
rdoc.rdoc_files.include('README*')
|
48
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
-
end
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/usesguid.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
-
|
3
|
+
|
4
4
|
require 'usesguid/active_record_extensions'
|
5
5
|
require 'usesguid/uuid22'
|
6
6
|
require 'usesguid/uuid_mysql'
|
7
|
+
require 'usesguid/uuid_sqlserver'
|
7
8
|
require 'usesguid/uuidtools'
|
8
9
|
|
9
10
|
module Usesguid
|
10
11
|
VERSION = '1.0.0'
|
11
12
|
end
|
12
13
|
|
13
|
-
ActiveRecord::Base.class_eval { include Usesguid::ActiveRecordExtensions } if defined?( ActiveRecord::Base )
|
14
|
+
ActiveRecord::Base.class_eval { include Usesguid::ActiveRecordExtensions } if defined?( ActiveRecord::Base )
|
@@ -6,47 +6,54 @@
|
|
6
6
|
# 3. set the id before create instead of after initialize
|
7
7
|
#
|
8
8
|
# MIT License
|
9
|
-
|
10
|
-
#require 'uuid22'
|
11
|
-
#require 'uuid_mysql'
|
12
|
-
|
13
9
|
module Usesguid
|
14
10
|
module ActiveRecordExtensions
|
15
|
-
|
16
|
-
#def self.append_features( base )
|
11
|
+
|
17
12
|
def self.included( base )
|
18
13
|
super
|
19
14
|
base.extend( ClassMethods )
|
20
15
|
end
|
21
16
|
|
22
|
-
|
17
|
+
|
23
18
|
module ClassMethods
|
24
|
-
|
19
|
+
|
25
20
|
# guid_generator can be :timestamp or :mysql
|
26
21
|
def guid_generator=(generator); class_eval { @guid_generator = generator } end
|
27
22
|
def guid_generator; class_eval { @guid_generator || :timestamp } end
|
28
|
-
|
23
|
+
|
24
|
+
def guid_compression=(compression); class_eval { @guid_compression = compression } end
|
25
|
+
def guid_compression; class_eval { @guid_compression || 's' } end
|
26
|
+
|
27
|
+
def guid_column=(column); class_eval { @guid_column = column } end
|
28
|
+
def guid_column; class_eval { @guid_column || 'id' } end
|
29
|
+
|
29
30
|
def usesguid(options = {})
|
30
|
-
|
31
|
+
options[:as] ||= :primary_key
|
32
|
+
|
31
33
|
class_eval do
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
if options[:as] == :primary_key && options[:column]
|
35
|
+
self.primary_key = options[:column]
|
36
|
+
end
|
37
|
+
|
38
|
+
before_validation :assign_guid
|
35
39
|
|
36
|
-
# Give this record a guid id. Public method so people can call it before save if necessary.
|
37
40
|
def assign_guid
|
38
|
-
self[
|
39
|
-
|
40
|
-
|
41
|
-
else raise "Unrecognized guid generator '#{ActiveRecord::Base.guid_generator.to_s}'"
|
42
|
-
end.to_s22
|
41
|
+
self[ActiveRecord::Base.guid_column] ||= (ActiveRecord::Base.guid_generator == :database ?
|
42
|
+
UUID.send( "#{ActiveRecord::Base.connection.adapter_name.downcase}_create" ) :
|
43
|
+
UUID.timestamp_create).send( "to_#{ActiveRecord::Base.guid_compression}" )
|
43
44
|
end
|
44
45
|
|
45
46
|
end
|
46
47
|
|
47
48
|
end
|
48
49
|
|
50
|
+
def validate_guid( options={} )
|
51
|
+
validates_presence_of( ActiveRecord::Base.guid_column )
|
52
|
+
validates_uniqueness_of( ActiveRecord::Base.guid_column )
|
53
|
+
validates_length_of( ActiveRecord::Base.guid_column, :maximum => (ActiveRecord::Base.guid_compression == 's22' ? 22 : 36), :allow_blank => true )
|
54
|
+
end
|
55
|
+
|
49
56
|
end
|
50
|
-
|
57
|
+
|
51
58
|
end
|
52
|
-
end
|
59
|
+
end
|
data/lib/usesguid/uuid22.rb
CHANGED
@@ -7,7 +7,8 @@ class UUID
|
|
7
7
|
|
8
8
|
# Make an array of 64 URL-safe characters
|
9
9
|
@@chars64=('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a + ['-','_']
|
10
|
-
|
10
|
+
|
11
|
+
# return a 22 byte URL-safe string, encoded six bits at a time using 64 characters
|
11
12
|
def to_s22
|
12
13
|
integer=self.to_i
|
13
14
|
rval=''
|
@@ -18,7 +19,8 @@ class UUID
|
|
18
19
|
end
|
19
20
|
return rval.reverse
|
20
21
|
end
|
21
|
-
|
22
|
+
|
23
|
+
# Create a new UUID from a 22char string
|
22
24
|
def self.parse22(s)
|
23
25
|
# get the integer representation
|
24
26
|
integer=0
|
@@ -39,5 +41,6 @@ class UUID
|
|
39
41
|
end
|
40
42
|
return new(time_low, time_mid, time_hi_and_version,
|
41
43
|
clock_seq_hi_and_reserved, clock_seq_low, nodes)
|
42
|
-
end
|
44
|
+
end
|
45
|
+
|
43
46
|
end
|
data/lib/usesguid/uuid_mysql.rb
CHANGED
@@ -2,26 +2,29 @@
|
|
2
2
|
# Written by Brian Morearty
|
3
3
|
# MIT License
|
4
4
|
|
5
|
-
#require 'uuidtools'
|
6
|
-
|
7
5
|
class UUID
|
8
6
|
|
9
7
|
BUCKET_SIZE = 50
|
10
8
|
@@guid_bucket_mutex = Mutex.new
|
11
9
|
@@guid_bucket = nil
|
12
|
-
|
10
|
+
|
13
11
|
# We'll retrieve a bunch of guids at a time to reduce the # of DB round-trips.
|
14
12
|
# If the guid bucket is empty, re-fill it by calling MySQL. Then return a guid.
|
15
|
-
def
|
13
|
+
def self.mysql_create(connection=ActiveRecord::Base.connection)
|
16
14
|
raise "UUID.mysql_create only works with MySQL" unless connection.adapter_name.downcase =~ /mysql/
|
15
|
+
|
17
16
|
@@guid_bucket_mutex.synchronize do
|
18
17
|
if @@guid_bucket.blank?
|
19
18
|
uuid_functions = Array.new(BUCKET_SIZE, "UUID()")
|
20
|
-
@@guid_bucket = connection.execute("SELECT #{uuid_functions.join(',')}").
|
19
|
+
@@guid_bucket = connection.execute("SELECT #{uuid_functions.join(',')}").first
|
21
20
|
end
|
22
|
-
# My tests show shift is much faster than slice!(0), pop, or delete_at(0)
|
21
|
+
# My tests show shift is much faster than slice!(0), pop, or delete_at(0)
|
23
22
|
parse @@guid_bucket.shift
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
26
|
+
def self.mysql2_create(connection=ActiveRecord::Base.connection)
|
27
|
+
mysql_create connection
|
28
|
+
end
|
29
|
+
|
27
30
|
end
|
data/lib/usesguid/uuidtools.rb
CHANGED
@@ -34,58 +34,58 @@ require 'digest/md5'
|
|
34
34
|
# Because it's impossible to hype a UUID generator on its genuine merits,
|
35
35
|
# I give you... Really bad ASCII art in the comments:
|
36
36
|
#
|
37
|
-
#
|
38
|
-
# \
|
39
|
-
# /
|
40
|
-
# +
|
41
|
-
# ]
|
42
|
-
# ]
|
43
|
-
# |
|
44
|
-
# /
|
45
|
-
# Mp___
|
46
|
-
# `~0NNp,
|
47
|
-
# __ggM'
|
48
|
-
# g0M~"`
|
49
|
-
# ]0M*-
|
50
|
-
#
|
51
|
-
# ___
|
52
|
-
# _g000M00g,
|
53
|
-
# j0M~ ~M&
|
54
|
-
# j0M" ~N,
|
55
|
-
# j0P M&
|
56
|
-
# jM 1
|
57
|
-
# j0 ]1
|
58
|
-
# .0P 0,
|
59
|
-
# 00' M&
|
60
|
-
# 0M ]0L
|
61
|
-
# ]0f ___ M0
|
62
|
-
# M0NN0M00MMM~"'M 0&
|
63
|
-
# `~ ~0 ]0,
|
64
|
-
# ]M ]0&
|
65
|
-
# M& M0,
|
66
|
-
# ____gp_ M& M0_
|
67
|
-
# __p0MPM8MM&_ M/ ^0&_
|
68
|
-
# gN"` M0N_j0, MM&__
|
69
|
-
# _gF `~M0P` __ M00g
|
70
|
-
# g0' gM0&, ~M0&
|
71
|
-
# _pM` 0, ]M1 "00&
|
72
|
-
# _00 /g1MMgj01 ]0MI
|
73
|
-
# _0F t"M,7MMM 00I
|
74
|
-
# g0' _ N&j& 40'
|
75
|
-
# g0' _p0Mq_ ' N0QQNM#g,
|
76
|
-
# 0' _g0000000g__ ~M@MMM000g
|
77
|
-
# f _jM00@` ~M0000Mgppg, "P00&
|
78
|
-
# | g000~ `~M000000&_ ~0&
|
79
|
-
# ]M _M00F "00MM` ~#&
|
80
|
-
# `0L m000F #E "0f
|
81
|
-
# 9r j000M` 40, 00
|
82
|
-
# ]0g_ j00M` ^M0MNggp#gqpg M0&
|
83
|
-
# ~MPM0f ~M000000000g_ ,_ygg&M00f
|
84
|
-
# `~~~M00000000000000
|
85
|
-
# `M0000000000f
|
86
|
-
# ~@@@MF~`
|
87
|
-
#
|
88
|
-
#
|
37
|
+
#
|
38
|
+
# \
|
39
|
+
# /
|
40
|
+
# +
|
41
|
+
# ]
|
42
|
+
# ]
|
43
|
+
# |
|
44
|
+
# /
|
45
|
+
# Mp___
|
46
|
+
# `~0NNp,
|
47
|
+
# __ggM'
|
48
|
+
# g0M~"`
|
49
|
+
# ]0M*-
|
50
|
+
#
|
51
|
+
# ___
|
52
|
+
# _g000M00g,
|
53
|
+
# j0M~ ~M&
|
54
|
+
# j0M" ~N,
|
55
|
+
# j0P M&
|
56
|
+
# jM 1
|
57
|
+
# j0 ]1
|
58
|
+
# .0P 0,
|
59
|
+
# 00' M&
|
60
|
+
# 0M ]0L
|
61
|
+
# ]0f ___ M0
|
62
|
+
# M0NN0M00MMM~"'M 0&
|
63
|
+
# `~ ~0 ]0,
|
64
|
+
# ]M ]0&
|
65
|
+
# M& M0,
|
66
|
+
# ____gp_ M& M0_
|
67
|
+
# __p0MPM8MM&_ M/ ^0&_
|
68
|
+
# gN"` M0N_j0, MM&__
|
69
|
+
# _gF `~M0P` __ M00g
|
70
|
+
# g0' gM0&, ~M0&
|
71
|
+
# _pM` 0, ]M1 "00&
|
72
|
+
# _00 /g1MMgj01 ]0MI
|
73
|
+
# _0F t"M,7MMM 00I
|
74
|
+
# g0' _ N&j& 40'
|
75
|
+
# g0' _p0Mq_ ' N0QQNM#g,
|
76
|
+
# 0' _g0000000g__ ~M@MMM000g
|
77
|
+
# f _jM00@` ~M0000Mgppg, "P00&
|
78
|
+
# | g000~ `~M000000&_ ~0&
|
79
|
+
# ]M _M00F "00MM` ~#&
|
80
|
+
# `0L m000F #E "0f
|
81
|
+
# 9r j000M` 40, 00
|
82
|
+
# ]0g_ j00M` ^M0MNggp#gqpg M0&
|
83
|
+
# ~MPM0f ~M000000000g_ ,_ygg&M00f
|
84
|
+
# `~~~M00000000000000
|
85
|
+
# `M0000000000f
|
86
|
+
# ~@@@MF~`
|
87
|
+
#
|
88
|
+
#
|
89
89
|
|
90
90
|
#= uuidtools.rb
|
91
91
|
#
|
@@ -108,7 +108,7 @@ class UUID
|
|
108
108
|
@@last_clock_sequence = nil
|
109
109
|
@@state_file = nil
|
110
110
|
@@mutex = Mutex.new
|
111
|
-
|
111
|
+
|
112
112
|
def initialize(time_low, time_mid, time_hi_and_version,
|
113
113
|
clock_seq_hi_and_reserved, clock_seq_low, nodes)
|
114
114
|
unless time_low >= 0 && time_low < 4294967296
|
@@ -137,7 +137,7 @@ class UUID
|
|
137
137
|
unless nodes.respond_to? :size
|
138
138
|
raise ArgumentError,
|
139
139
|
"Expected nodes to respond to :size."
|
140
|
-
end
|
140
|
+
end
|
141
141
|
unless nodes.size == 6
|
142
142
|
raise ArgumentError,
|
143
143
|
"Expected nodes to have size of 6."
|
@@ -156,14 +156,14 @@ class UUID
|
|
156
156
|
@clock_seq_low = clock_seq_low
|
157
157
|
@nodes = nodes
|
158
158
|
end
|
159
|
-
|
159
|
+
|
160
160
|
attr_accessor :time_low
|
161
161
|
attr_accessor :time_mid
|
162
162
|
attr_accessor :time_hi_and_version
|
163
163
|
attr_accessor :clock_seq_hi_and_reserved
|
164
164
|
attr_accessor :clock_seq_low
|
165
165
|
attr_accessor :nodes
|
166
|
-
|
166
|
+
|
167
167
|
# Parses a UUID from a string.
|
168
168
|
def UUID.parse(uuid_string)
|
169
169
|
unless uuid_string.kind_of? String
|
@@ -261,7 +261,7 @@ class UUID
|
|
261
261
|
clock_seq_low = clock_sequence & 0xFF;
|
262
262
|
clock_seq_hi_and_reserved = (clock_sequence & 0x3F00) >> 8
|
263
263
|
clock_seq_hi_and_reserved |= 0x80
|
264
|
-
|
264
|
+
|
265
265
|
return UUID.new(time_low, time_mid, time_hi_and_version,
|
266
266
|
clock_seq_hi_and_reserved, clock_seq_low, nodes)
|
267
267
|
end
|
@@ -271,12 +271,12 @@ class UUID
|
|
271
271
|
def UUID.md5_create(namespace, name)
|
272
272
|
return UUID.create_from_hash(Digest::MD5, namespace, name)
|
273
273
|
end
|
274
|
-
|
274
|
+
|
275
275
|
# Creates a UUID using the SHA1 hash. (Version 5)
|
276
276
|
def UUID.sha1_create(namespace, name)
|
277
277
|
return UUID.create_from_hash(Digest::SHA1, namespace, name)
|
278
278
|
end
|
279
|
-
|
279
|
+
|
280
280
|
# This method applies only to version 1 UUIDs.
|
281
281
|
# Checks if the node ID was generated from a random number
|
282
282
|
# or from an IEEE 802 address (MAC address).
|
@@ -287,7 +287,7 @@ class UUID
|
|
287
287
|
return false if self.version != 1
|
288
288
|
return ((self.nodes.first & 0x01) == 1)
|
289
289
|
end
|
290
|
-
|
290
|
+
|
291
291
|
# Returns true if this UUID is the
|
292
292
|
# nil UUID (00000000-0000-0000-0000-000000000000).
|
293
293
|
def nil_uuid?
|
@@ -301,7 +301,7 @@ class UUID
|
|
301
301
|
end
|
302
302
|
return true
|
303
303
|
end
|
304
|
-
|
304
|
+
|
305
305
|
# Returns the UUID version type.
|
306
306
|
# Possible values:
|
307
307
|
# 1 - Time-based with unique or random host identifier
|
@@ -331,7 +331,7 @@ class UUID
|
|
331
331
|
end
|
332
332
|
return (result >> 6)
|
333
333
|
end
|
334
|
-
|
334
|
+
|
335
335
|
# Returns true if this UUID is valid.
|
336
336
|
def valid?
|
337
337
|
if [0b000, 0b100, 0b110, 0b111].include?(self.variant) &&
|
@@ -341,7 +341,7 @@ class UUID
|
|
341
341
|
return false
|
342
342
|
end
|
343
343
|
end
|
344
|
-
|
344
|
+
|
345
345
|
# Returns the IEEE 802 address used to generate this UUID or
|
346
346
|
# nil if a MAC address was not used.
|
347
347
|
def mac_address
|
@@ -351,7 +351,7 @@ class UUID
|
|
351
351
|
sprintf("%2.2x", node)
|
352
352
|
end).join(":")
|
353
353
|
end
|
354
|
-
|
354
|
+
|
355
355
|
# Returns the timestamp used to generate this UUID
|
356
356
|
def timestamp
|
357
357
|
return nil if self.version != 1
|
@@ -363,7 +363,7 @@ class UUID
|
|
363
363
|
return Time.at(
|
364
364
|
(gmt_timestamp_100_nanoseconds - 0x01B21DD213814000) / 10000000.0)
|
365
365
|
end
|
366
|
-
|
366
|
+
|
367
367
|
# Compares two UUIDs lexically
|
368
368
|
def <=>(other_uuid)
|
369
369
|
check = self.time_low <=> other_uuid.time_low
|
@@ -387,22 +387,22 @@ class UUID
|
|
387
387
|
end
|
388
388
|
return 0
|
389
389
|
end
|
390
|
-
|
390
|
+
|
391
391
|
# Returns a representation of the object's state
|
392
392
|
def inspect
|
393
393
|
return "#<UUID:0x#{self.object_id.to_s(16)} UUID:#{self.to_s}>"
|
394
394
|
end
|
395
|
-
|
395
|
+
|
396
396
|
# Returns the hex digest of the UUID object.
|
397
397
|
def hexdigest
|
398
398
|
return self.to_i.to_s(16)
|
399
399
|
end
|
400
|
-
|
400
|
+
|
401
401
|
# Returns the raw bytes that represent this UUID.
|
402
402
|
def raw
|
403
403
|
return UUID.convert_int_to_byte_string(self.to_i, 16)
|
404
404
|
end
|
405
|
-
|
405
|
+
|
406
406
|
# Returns a string representation for this UUID.
|
407
407
|
def to_s
|
408
408
|
result = sprintf("%8.8x-%4.4x-%4.4x-%2.2x%2.2x-", @time_low, @time_mid,
|
@@ -412,7 +412,7 @@ class UUID
|
|
412
412
|
end
|
413
413
|
return result
|
414
414
|
end
|
415
|
-
|
415
|
+
|
416
416
|
# Returns an integer representation for this UUID.
|
417
417
|
def to_i
|
418
418
|
bytes = (time_low << 96) + (time_mid << 80) +
|
@@ -423,7 +423,7 @@ class UUID
|
|
423
423
|
end
|
424
424
|
return bytes
|
425
425
|
end
|
426
|
-
|
426
|
+
|
427
427
|
# Returns a URI for this UUID.
|
428
428
|
def to_uri
|
429
429
|
return URI.parse(self.to_uri_string)
|
@@ -433,7 +433,7 @@ class UUID
|
|
433
433
|
def to_uri_string
|
434
434
|
return "urn:uuid:#{self.to_s}"
|
435
435
|
end
|
436
|
-
|
436
|
+
|
437
437
|
def UUID.create_from_hash(hash_class, namespace, name) #:nodoc:
|
438
438
|
if hash_class == Digest::MD5
|
439
439
|
version = 3
|
@@ -449,7 +449,7 @@ class UUID
|
|
449
449
|
hash_string = hash.to_s[0..31]
|
450
450
|
new_uuid = UUID.parse("#{hash_string[0..7]}-#{hash_string[8..11]}-" +
|
451
451
|
"#{hash_string[12..15]}-#{hash_string[16..19]}-#{hash_string[20..31]}")
|
452
|
-
|
452
|
+
|
453
453
|
new_uuid.time_hi_and_version &= 0x0FFF
|
454
454
|
new_uuid.time_hi_and_version |= (version << 12)
|
455
455
|
new_uuid.clock_seq_hi_and_reserved &= 0x3F
|
@@ -497,7 +497,7 @@ class UUID
|
|
497
497
|
end
|
498
498
|
end
|
499
499
|
end
|
500
|
-
|
500
|
+
|
501
501
|
# Returns 128 bits of highly unpredictable data.
|
502
502
|
# The random number generator isn't perfect, but it's
|
503
503
|
# much, much better than the built-in pseudorandom number generators.
|
@@ -536,7 +536,7 @@ class UUID
|
|
536
536
|
hash.update(performance.inspect)
|
537
537
|
return UUID.convert_int_to_byte_string(hash.to_s[4..35].to_i(16), 16)
|
538
538
|
end
|
539
|
-
|
539
|
+
|
540
540
|
def UUID.convert_int_to_byte_string(integer, size) #:nodoc:
|
541
541
|
byte_string = ""
|
542
542
|
for i in 0..(size - 1)
|
@@ -558,4 +558,4 @@ end
|
|
558
558
|
UUID_DNS_NAMESPACE = UUID.parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
|
559
559
|
UUID_URL_NAMESPACE = UUID.parse("6ba7b811-9dad-11d1-80b4-00c04fd430c8")
|
560
560
|
UUID_OID_NAMESPACE = UUID.parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8")
|
561
|
-
UUID_X500_NAMESPACE = UUID.parse("6ba7b814-9dad-11d1-80b4-00c04fd430c8")
|
561
|
+
UUID_X500_NAMESPACE = UUID.parse("6ba7b814-9dad-11d1-80b4-00c04fd430c8")
|
data/usesguid.gemspec
CHANGED
@@ -1,58 +1,23 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'usesguid/version'
|
5
5
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "usesguid"
|
8
|
+
spec.version = Usesguid::VERSION
|
9
|
+
spec.authors = ["C. Jason Harrelson"]
|
10
|
+
spec.email = ["jason@lookforwardenterprises.com"]
|
11
|
+
spec.description = %q{A much faster version of the usesguid plugin for Rails ported to a gem (uses database for GUID generation)}
|
12
|
+
spec.summary = %q{A much faster version of the usesguid plugin for Rails ported to a gem}
|
13
|
+
spec.homepage = "https://github.com/midas/usesguid"
|
14
|
+
spec.license = "MIT"
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
s.email = %q{jason@lookforwardenterprises.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
"History.txt",
|
21
|
-
"LICENSE",
|
22
|
-
"README.rdoc",
|
23
|
-
"Rakefile",
|
24
|
-
"VERSION",
|
25
|
-
"lib/usesguid.rb",
|
26
|
-
"lib/usesguid/active_record_extensions.rb",
|
27
|
-
"lib/usesguid/uuid22.rb",
|
28
|
-
"lib/usesguid/uuid_mysql.rb",
|
29
|
-
"lib/usesguid/uuidtools.rb",
|
30
|
-
"script/console",
|
31
|
-
"spec/spec_helper.rb",
|
32
|
-
"spec/usesguid_spec.rb",
|
33
|
-
"usesguid.gemspec"
|
34
|
-
]
|
35
|
-
s.homepage = %q{http://github.com/midas/usesguid}
|
36
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
-
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version = %q{1.3.5}
|
39
|
-
s.summary = %q{A much faster version of the usesguid plugin for Rails}
|
40
|
-
s.test_files = [
|
41
|
-
"spec/spec_helper.rb",
|
42
|
-
"spec/usesguid_spec.rb"
|
43
|
-
]
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
44
20
|
|
45
|
-
|
46
|
-
|
47
|
-
s.specification_version = 3
|
48
|
-
|
49
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
50
|
-
s.add_development_dependency(%q<rspec>, [">= 0"])
|
51
|
-
else
|
52
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
53
|
-
end
|
54
|
-
else
|
55
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
56
|
-
end
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
57
23
|
end
|
58
|
-
|
metadata
CHANGED
@@ -1,82 +1,103 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: usesguid
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
|
-
authors:
|
7
|
-
-
|
8
|
-
- Demetrio Nunes
|
9
|
-
- Robert Aman
|
10
|
-
- C. Jason Harrelson(midas)
|
7
|
+
authors:
|
8
|
+
- C. Jason Harrelson
|
11
9
|
autorequire:
|
12
10
|
bindir: bin
|
13
11
|
cert_chain: []
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
date: 2013-07-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
20
22
|
type: :development
|
21
|
-
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: A much faster version of the usesguid plugin for Rails ported to a gem
|
47
|
+
(uses database for GUID generation)
|
48
|
+
email:
|
49
|
+
- jason@lookforwardenterprises.com
|
30
50
|
executables: []
|
31
|
-
|
32
51
|
extensions: []
|
33
|
-
|
34
|
-
|
35
|
-
-
|
36
|
-
-
|
37
|
-
|
38
|
-
- History.txt
|
39
|
-
- LICENSE
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
40
57
|
- README.rdoc
|
41
58
|
- Rakefile
|
42
|
-
- VERSION
|
43
59
|
- lib/usesguid.rb
|
44
60
|
- lib/usesguid/active_record_extensions.rb
|
45
61
|
- lib/usesguid/uuid22.rb
|
46
62
|
- lib/usesguid/uuid_mysql.rb
|
63
|
+
- lib/usesguid/uuid_sqlserver.rb
|
47
64
|
- lib/usesguid/uuidtools.rb
|
65
|
+
- lib/usesguid/version.rb
|
48
66
|
- script/console
|
49
67
|
- spec/spec_helper.rb
|
50
68
|
- spec/usesguid_spec.rb
|
51
69
|
- usesguid.gemspec
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
70
|
+
homepage: https://github.com/midas/usesguid
|
71
|
+
licenses:
|
72
|
+
- MIT
|
56
73
|
post_install_message:
|
57
|
-
rdoc_options:
|
58
|
-
|
59
|
-
require_paths:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
60
76
|
- lib
|
61
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
hash: -2136879917900583215
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
hash: -2136879917900583215
|
73
95
|
requirements: []
|
74
|
-
|
75
96
|
rubyforge_project:
|
76
|
-
rubygems_version: 1.
|
97
|
+
rubygems_version: 1.8.25
|
77
98
|
signing_key:
|
78
99
|
specification_version: 3
|
79
|
-
summary: A much faster version of the usesguid plugin for Rails
|
80
|
-
test_files:
|
100
|
+
summary: A much faster version of the usesguid plugin for Rails ported to a gem
|
101
|
+
test_files:
|
81
102
|
- spec/spec_helper.rb
|
82
103
|
- spec/usesguid_spec.rb
|
data/History.txt
DELETED
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.0.0
|