simple_uuid 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,13 +1,24 @@
1
- v0.3.0 Add option `:randomize` to turn off the random part of the UUID
1
+ v0.4.0
2
+ - Fix comparison of time UUIDs (@muirmanders, #13)
3
+ - Moved to the cassandra-rb github project
2
4
 
3
- v0.2.0 perf optimizations for cassandra cql
5
+ v0.3.0
6
+ - Add option `:randomize` to turn off the random part of the UUID
4
7
 
5
- v0.1.2 add license file
8
+ v0.2.0
9
+ - perf optimizations for cassandra cql
6
10
 
7
- v0.1.1 fix problem with ruby 1.9 [Aanand Prasad]
11
+ v0.1.2
12
+ - add license file
8
13
 
9
- v0.1.0 move UUID class into a SimpleUUID module
14
+ v0.1.1
15
+ - fix problem with ruby 1.9 [Aanand Prasad]
10
16
 
11
- v0.0.2 Update equality test for compatibility with Cassandra gem.
17
+ v0.1.0
18
+ - move UUID class into a SimpleUUID module
12
19
 
13
- v0.0.1 Initial extraction from the cassandra gem.
20
+ v0.0.2
21
+ - Update equality test for compatibility with Cassandra gem.
22
+
23
+ v0.0.1
24
+ - Initial extraction from the cassandra gem.
@@ -32,6 +32,6 @@ Install the gem:
32
32
 
33
33
  == Reporting problems
34
34
 
35
- The support forum is here[http://github.com/ryanking/simple_uuid/issues].
35
+ The support forum is here[http://github.com/cassandra-rb/simple_uuid/issues].
36
36
 
37
37
  Patches and contributions are very welcome.
data/Rakefile CHANGED
@@ -3,8 +3,6 @@ require 'echoe'
3
3
  Echoe.new('simple_uuid') do |e|
4
4
  e.author = 'Ryan King, Evan Weaver'
5
5
  e.description = 'Simple, scalable UUID generation.'
6
- e.email = 'ryan@twitter.com'
7
6
  e.rubygems_version = ">= 0.8"
8
- e.project = "fauna"
9
7
  e.retain_gemspec = true
10
8
  end
@@ -27,7 +27,7 @@ module SimpleUUID
27
27
  when String
28
28
  case bytes.size
29
29
  when 16 # Raw byte array
30
- @bytes = bytes
30
+ @bytes = bytes.respond_to?(:force_encoding) ? bytes.force_encoding("ASCII-8BIT") : bytes
31
31
  when 36 # Human-readable UUID representation; inverse of #to_guid
32
32
  elements = bytes.split("-")
33
33
  raise TypeError, "Expected #{bytes.inspect} to cast to a #{self.class} (malformed UUID representation)" if elements.size != 5
@@ -56,11 +56,19 @@ module SimpleUUID
56
56
 
57
57
  # Top 3 bytes reserved
58
58
  if opts[:randomize] == false
59
- byte_array += [
60
- 0 | VARIANT,
61
- 0,
62
- 0
63
- ]
59
+ byte_array += if !opts[:salt].nil?
60
+ clock_h, clock_l, node_h, node_l =
61
+ opts[:salt].to_s.unpack("CCnN")
62
+
63
+ clock = [
64
+ clock_h | VARIANT,
65
+ clock_l
66
+ ].pack("n").unpack("n").first
67
+
68
+ [ clock, node_h, node_l ]
69
+ else
70
+ [ 0 | VARIANT, 0, 0 ]
71
+ end
64
72
  else
65
73
  byte_array += [
66
74
  rand(2**13) | VARIANT,
@@ -109,11 +117,15 @@ module SimpleUUID
109
117
  end
110
118
 
111
119
  def <=>(other)
112
- total_usecs <=> other.send(:total_usecs)
113
- end
114
-
115
- def ==(other)
116
- to_s == other.to_s
120
+ me = to_s.unpack('Nn2C*')
121
+ him = other.to_s.unpack('Nn2C*')
122
+ # swap most significant time bits to front
123
+ me[0], me[2], him[0], him[2] = me[2], me[0], him[2], him[0]
124
+ me.zip(him) do |m, h|
125
+ comp = m <=> h
126
+ return comp if comp != 0
127
+ end
128
+ return 0
117
129
  end
118
130
 
119
131
  def inspect(long = false)
@@ -2,22 +2,20 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "simple_uuid"
5
- s.version = "0.3.0"
5
+ s.version = "0.4.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0.8") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Ryan King, Evan Weaver"]
9
- s.date = "2012-11-27"
10
9
  s.description = "Simple, scalable UUID generation."
11
- s.email = "ryan@twitter.com"
12
10
  s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.rdoc", "lib/simple_uuid.rb"]
13
11
  s.files = ["CHANGELOG", "LICENSE", "Manifest", "README.rdoc", "Rakefile", "lib/simple_uuid.rb", "simple_uuid.gemspec", "test/test_uuid.rb"]
14
- s.homepage = "http://fauna.github.com/fauna/simple_uuid/"
12
+ s.homepage = "https://github.com/cassandra-rb/simple_uuid"
15
13
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Simple_uuid", "--main", "README.rdoc"]
16
14
  s.require_paths = ["lib"]
17
- s.rubyforge_project = "fauna"
18
15
  s.rubygems_version = "1.8.24"
19
16
  s.summary = "Simple, scalable UUID generation."
20
17
  s.test_files = ["test/test_uuid.rb"]
18
+ s.licenses = ['Apache']
21
19
 
22
20
  if s.respond_to? :specification_version then
23
21
  s.specification_version = 3
@@ -1,5 +1,7 @@
1
1
  require 'test/unit'
2
+ require 'digest/md5'
2
3
  require 'simple_uuid'
4
+
3
5
  include SimpleUUID
4
6
 
5
7
  class UUIDTest < Test::Unit::TestCase
@@ -18,6 +20,29 @@ class UUIDTest < Test::Unit::TestCase
18
20
  assert_equal uuid, UUID.new(uuid.to_guid)
19
21
  end
20
22
 
23
+ def test_equality_with_encoding
24
+ return unless "".respond_to? :force_encoding
25
+
26
+ utf8_uuid_bytes = "\xFD\x17\x1F\xA6=O\x11\xE2\x92\x13pV\x81\xBB\x05\x87".force_encoding("UTF-8")
27
+ binary_uuid_bytes = "\xFD\x17\x1F\xA6=O\x11\xE2\x92\x13pV\x81\xBB\x05\x87".force_encoding("ASCII-8BIT")
28
+
29
+ assert_equal UUID.new(utf8_uuid_bytes), UUID.new(binary_uuid_bytes)
30
+ end
31
+
32
+ def test_salt
33
+ tnow = Time.now
34
+ salt = Digest::MD5.new.update("some salt")
35
+ tthen = Time.now
36
+
37
+ uuid1 = UUID.new(tnow, :randomize => false, :salt => salt.digest)
38
+ uuid2 = UUID.new(tthen, :randomize => false, :salt => salt.digest)
39
+
40
+ assert_equal uuid1.to_time, tnow
41
+ assert_equal uuid2.to_time, tthen
42
+ assert_equal uuid1.bytes[8..-1], uuid2.bytes[8..-1]
43
+ assert uuid2 > uuid1
44
+ end
45
+
21
46
  def test_uuid_error
22
47
  assert_raises(TypeError) do
23
48
  UUID.new("bogus")
@@ -48,13 +73,13 @@ class UUIDTest < Test::Unit::TestCase
48
73
  assert current_uuid >= current_uuid
49
74
  assert future_uuid >= current_uuid
50
75
  end
51
-
76
+
52
77
  def test_to_time
53
78
  ts = Time.new
54
79
  uuid = UUID.new(ts)
55
80
  assert_equal ts, uuid.to_time
56
81
  end
57
-
82
+
58
83
  def test_total_usecs
59
84
  uuid = UUID.new
60
85
  assert_equal uuid.send(:total_usecs), UUID.total_usecs(uuid.bytes)
@@ -66,4 +91,21 @@ class UUIDTest < Test::Unit::TestCase
66
91
  assert_not_equal UUID.new(t), UUID.new(t)
67
92
  assert_equal UUID.new(t, randomize: false), UUID.new(t, randomize: false)
68
93
  end
94
+
95
+ def test_identical_times
96
+ t = Time.now
97
+ u1 = UUID.new(t)
98
+ u2 = UUID.new(t)
99
+
100
+ assert_not_equal u1, u2
101
+ assert_equal u1, UUID.new(u1) # sanity
102
+ assert_not_equal 0, u1 <=> u2
103
+ assert_equal u1.to_time, u2.to_time
104
+
105
+ if u1.to_s[-8, 8] > u2.to_s[-8, 8]
106
+ assert u1 > u2
107
+ else
108
+ assert u2 > u1
109
+ end
110
+ end
69
111
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_uuid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
8
- - 3
7
+ - 4
9
8
  - 0
10
- version: 0.3.0
9
+ version: 0.4.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Ryan King, Evan Weaver
@@ -15,11 +14,12 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2012-11-27 00:00:00 Z
17
+ date: 2013-10-10 00:00:00 -07:00
18
+ default_executable:
19
19
  dependencies: []
20
20
 
21
21
  description: Simple, scalable UUID generation.
22
- email: ryan@twitter.com
22
+ email:
23
23
  executables: []
24
24
 
25
25
  extensions: []
@@ -38,9 +38,10 @@ files:
38
38
  - lib/simple_uuid.rb
39
39
  - simple_uuid.gemspec
40
40
  - test/test_uuid.rb
41
- homepage: http://fauna.github.com/fauna/simple_uuid/
42
- licenses: []
43
-
41
+ has_rdoc: true
42
+ homepage: https://github.com/cassandra-rb/simple_uuid
43
+ licenses:
44
+ - Apache
44
45
  post_install_message:
45
46
  rdoc_options:
46
47
  - --line-numbers
@@ -52,28 +53,24 @@ rdoc_options:
52
53
  require_paths:
53
54
  - lib
54
55
  required_ruby_version: !ruby/object:Gem::Requirement
55
- none: false
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
- hash: 3
60
59
  segments:
61
60
  - 0
62
61
  version: "0"
63
62
  required_rubygems_version: !ruby/object:Gem::Requirement
64
- none: false
65
63
  requirements:
66
64
  - - ">="
67
65
  - !ruby/object:Gem::Version
68
- hash: 27
69
66
  segments:
70
67
  - 0
71
68
  - 8
72
69
  version: "0.8"
73
70
  requirements: []
74
71
 
75
- rubyforge_project: fauna
76
- rubygems_version: 1.8.24
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.6
77
74
  signing_key:
78
75
  specification_version: 3
79
76
  summary: Simple, scalable UUID generation.