simple_uuid 0.2.0 → 0.3.0

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.
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.3.0 Add option `:randomize` to turn off the random part of the UUID
2
+
1
3
  v0.2.0 perf optimizations for cassandra cql
2
4
 
3
5
  v0.1.2 add license file
data/Manifest CHANGED
@@ -4,4 +4,5 @@ Manifest
4
4
  README.rdoc
5
5
  Rakefile
6
6
  lib/simple_uuid.rb
7
+ simple_uuid.gemspec
7
8
  test/test_uuid.rb
@@ -20,7 +20,7 @@ module SimpleUUID
20
20
 
21
21
  VARIANT = 0b1000_0000_0000_0000
22
22
 
23
- def initialize(bytes = nil)
23
+ def initialize(bytes = nil, opts = {})
24
24
  case bytes
25
25
  when self.class # UUID
26
26
  @bytes = bytes.to_s
@@ -48,16 +48,28 @@ module SimpleUUID
48
48
  when NilClass, Time
49
49
  time = (bytes || Time).stamp * 10 + GREGORIAN_EPOCH_OFFSET
50
50
  # See http://github.com/spectra/ruby-uuid/
51
- @bytes = [
51
+ byte_array = [
52
52
  time & 0xFFFF_FFFF,
53
53
  time >> 32,
54
54
  ((time >> 48) & 0x0FFF) | 0x1000,
55
- # Top 3 bytes reserved
56
- rand(2**13) | VARIANT,
57
- rand(2**16),
58
- rand(2**32)
59
- ].pack("NnnnnN")
55
+ ]
56
+
57
+ # Top 3 bytes reserved
58
+ if opts[:randomize] == false
59
+ byte_array += [
60
+ 0 | VARIANT,
61
+ 0,
62
+ 0
63
+ ]
64
+ else
65
+ byte_array += [
66
+ rand(2**13) | VARIANT,
67
+ rand(2**16),
68
+ rand(2**32)
69
+ ]
70
+ end
60
71
 
72
+ @bytes = byte_array.pack("NnnnnN")
61
73
  else
62
74
  raise TypeError, "Expected #{bytes.inspect} to cast to a #{self.class} (unknown source class)"
63
75
  end
@@ -1,23 +1,23 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  Gem::Specification.new do |s|
4
- s.name = %q{simple_uuid}
5
- s.version = "0.2.0"
4
+ s.name = "simple_uuid"
5
+ s.version = "0.3.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0.8") if s.respond_to? :required_rubygems_version=
8
- s.authors = [%q{Ryan King, Evan Weaver}]
9
- s.date = %q{2011-08-19}
10
- s.description = %q{Simple, scalable UUID generation.}
11
- s.email = %q{ryan@twitter.com}
12
- s.extra_rdoc_files = [%q{CHANGELOG}, %q{LICENSE}, %q{README.rdoc}, %q{lib/simple_uuid.rb}]
13
- s.files = [%q{CHANGELOG}, %q{LICENSE}, %q{Manifest}, %q{README.rdoc}, %q{Rakefile}, %q{lib/simple_uuid.rb}, %q{test/test_uuid.rb}, %q{simple_uuid.gemspec}]
14
- s.homepage = %q{http://fauna.github.com/fauna/simple_uuid/}
15
- s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Simple_uuid}, %q{--main}, %q{README.rdoc}]
16
- s.require_paths = [%q{lib}]
17
- s.rubyforge_project = %q{fauna}
18
- s.rubygems_version = %q{1.8.5}
19
- s.summary = %q{Simple, scalable UUID generation.}
20
- s.test_files = [%q{test/test_uuid.rb}]
8
+ s.authors = ["Ryan King, Evan Weaver"]
9
+ s.date = "2012-11-27"
10
+ s.description = "Simple, scalable UUID generation."
11
+ s.email = "ryan@twitter.com"
12
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.rdoc", "lib/simple_uuid.rb"]
13
+ 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/"
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Simple_uuid", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = "fauna"
18
+ s.rubygems_version = "1.8.24"
19
+ s.summary = "Simple, scalable UUID generation."
20
+ s.test_files = ["test/test_uuid.rb"]
21
21
 
22
22
  if s.respond_to? :specification_version then
23
23
  s.specification_version = 3
@@ -59,4 +59,11 @@ class UUIDTest < Test::Unit::TestCase
59
59
  uuid = UUID.new
60
60
  assert_equal uuid.send(:total_usecs), UUID.total_usecs(uuid.bytes)
61
61
  end
62
+
63
+ def test_no_jitter
64
+ t = Time.now
65
+
66
+ assert_not_equal UUID.new(t), UUID.new(t)
67
+ assert_equal UUID.new(t, randomize: false), UUID.new(t, randomize: false)
68
+ end
62
69
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_uuid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan King, Evan Weaver
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-19 00:00:00 Z
18
+ date: 2012-11-27 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Simple, scalable UUID generation.
@@ -36,8 +36,8 @@ files:
36
36
  - README.rdoc
37
37
  - Rakefile
38
38
  - lib/simple_uuid.rb
39
- - test/test_uuid.rb
40
39
  - simple_uuid.gemspec
40
+ - test/test_uuid.rb
41
41
  homepage: http://fauna.github.com/fauna/simple_uuid/
42
42
  licenses: []
43
43
 
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  requirements: []
74
74
 
75
75
  rubyforge_project: fauna
76
- rubygems_version: 1.8.5
76
+ rubygems_version: 1.8.24
77
77
  signing_key:
78
78
  specification_version: 3
79
79
  summary: Simple, scalable UUID generation.