torid 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afed761e9019552f02faa3669e3f495a4cf28545
4
- data.tar.gz: 4d35d92decf2c3ea6cc1f905f26e2ec298acbe4e
3
+ metadata.gz: 904f97e3e10a368d48b9ed1b56f3432b6ee7cf0a
4
+ data.tar.gz: 99f03c856b0d00bcbcaf0d795b9f41f851f4649b
5
5
  SHA512:
6
- metadata.gz: d33560130ca1e6f3d6c6a82cd19ee2bd5d90ef8ced357ccc44777b6c285b88fa1cf756972ebe1d88e5b5a8ae395e1001c862bf0ae7e9be4e66dd8f0bb21eddaf
7
- data.tar.gz: 94af487b8ba0c1533c998d08c34f65e5bfc803fc5527cf382bca181e52d576547cb4a8cfdd2927bfebee062c1e6f212b5ce17ccad475922a8299ba2ec30abefc
6
+ metadata.gz: 39f9398d44e8e80199117a3c119ada2186c151f5ee2f3373146178c600206c6d4a787527e581551d33181384595ce8e0bc31e2d6998250031be87dd72fc036b9
7
+ data.tar.gz: 208f6443b30679a1b54c6b26818c8b2c903f699195a7e8db3dec89d38c36cb54f805bdf2a9fe5aa94d4cb662edc1f773cbcc09239de13b6048043a62257a7a59
data/HISTORY.md CHANGED
@@ -1,4 +1,9 @@
1
1
  # Torid Changelog
2
+ ## Version 1.2.1 - 2014-09-13
3
+
4
+ * Fix bug where after a fork you could generate the same uuids in different
5
+ processes (copiousfreetime/torid#1)
6
+
2
7
  ## Version 1.2.0 - 2014-09-04
3
8
 
4
9
  * Added equivalence checking
data/lib/torid.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # that sort lexically in time order.
3
3
  module Torid
4
4
  # Public: The Version of the Torid library as a String
5
- VERSION = "1.2.0"
5
+ VERSION = "1.2.1"
6
6
 
7
7
  # Public: return the next Torid::UUID from the default Generator
8
8
  #
@@ -21,27 +21,40 @@ module Torid
21
21
  # Internal: The Clock instance used to get 64bit timestamps
22
22
  attr_reader :clock
23
23
 
24
- # Internal: The Node id of this instance
25
- attr_reader :node_id
26
-
27
24
  # Internal: Create a new Torid UUID Generator
28
25
  #
29
26
  # clock - an object that responds to `#tick` and returns a 64bit integer.
30
27
  # (default: Torid::Clock)
31
- # node_id - the 64bit node id of this node. (default: Generator.node_id)
28
+ # node_id - the 64bit node id of this node. (default: Generator.create_node_id)
32
29
  #
33
- def initialize( clock = Torid::Clock, node_id = Generator.node_id )
30
+ def initialize( clock = Torid::Clock, node_id = Generator.create_node_id )
34
31
  @clock = clock
35
32
  @node_id = node_id
33
+ @pid = Process.pid
36
34
  end
37
35
 
38
36
  # Public: Return the next UUID from this generator
39
37
  #
40
38
  # Returns Torid::UUID
41
39
  def next
42
- Torid::UUID.new( @clock.tick, @node_id )
40
+ Torid::UUID.new( clock.tick, node_id )
43
41
  end
44
42
 
43
+ # Public: Return the node id
44
+ #
45
+ # This also checks if the node id is still a valid node id, by checking
46
+ # the pid of the process and the pid of the last time the node id was
47
+ # generated.
48
+ #
49
+ # Returns the node_id
50
+ def node_id
51
+ current_pid = Process.pid
52
+ if current_pid != @pid then
53
+ @pid = current_pid
54
+ @node_id = Generator.create_node_id( @pid )
55
+ end
56
+ return @node_id
57
+ end
45
58
 
46
59
  # Internal: Generate a unique node identifier.
47
60
  #
@@ -55,9 +68,8 @@ module Torid
55
68
  # with the random bytes added by me.
56
69
  #
57
70
  # Returns a 64 bit Integer
58
- def self.create_node_id
71
+ def self.create_node_id( pid = Process.pid )
59
72
  hostname = Socket.gethostbyname( Socket.gethostname ).first
60
- pid = Process.pid
61
73
  random = SecureRandom.hex( 16 )
62
74
  FNV.new.fnv1a_64("#{hostname}-#{pid}-#{random}")
63
75
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: torid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Hinegardner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-04 00:00:00.000000000 Z
11
+ date: 2014-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fnv