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 +4 -4
- data/HISTORY.md +5 -0
- data/lib/torid.rb +1 -1
- data/lib/torid/generator.rb +20 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 904f97e3e10a368d48b9ed1b56f3432b6ee7cf0a
|
4
|
+
data.tar.gz: 99f03c856b0d00bcbcaf0d795b9f41f851f4649b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39f9398d44e8e80199117a3c119ada2186c151f5ee2f3373146178c600206c6d4a787527e581551d33181384595ce8e0bc31e2d6998250031be87dd72fc036b9
|
7
|
+
data.tar.gz: 208f6443b30679a1b54c6b26818c8b2c903f699195a7e8db3dec89d38c36cb54f805bdf2a9fe5aa94d4cb662edc1f773cbcc09239de13b6048043a62257a7a59
|
data/HISTORY.md
CHANGED
data/lib/torid.rb
CHANGED
data/lib/torid/generator.rb
CHANGED
@@ -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.
|
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.
|
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
|
-
|
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.
|
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-
|
11
|
+
date: 2014-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fnv
|