propertybase_id 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +3 -2
- data/lib/propertybase_id.rb +12 -24
- data/lib/propertybase_id/generator.rb +10 -14
- data/lib/propertybase_id/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d0822383ba08e57c55f45eb116a0577b49bccff
|
4
|
+
data.tar.gz: f672a9f1b0fa2a7ee724bb7a880079af0b026cf6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e9940e69dce5eac1844f63fdaa9ee50422be5e107da2d9f5220cbd1bee73a94129f11d0ca1d30a17df932e485afbaaaf125715dd5c81b95611b813e99c1bc3f
|
7
|
+
data.tar.gz: 8b040542ed0fccbdda7325c2e8a3966c8bf67e06bea2afe9342dabc6ddcca32fcf51b6f221193caf38bd49fa9cebc5debc9bd8a4ad40d5c5732f4d4250bb364b
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/lib/propertybase_id.rb
CHANGED
@@ -4,17 +4,13 @@ require "propertybase_id/mappings"
|
|
4
4
|
|
5
5
|
class PropertybaseId
|
6
6
|
attr_reader :object_id
|
7
|
-
attr_reader :host_id
|
8
7
|
attr_reader :time
|
9
|
-
attr_reader :
|
10
|
-
attr_reader :counter
|
8
|
+
attr_reader :random_int
|
11
9
|
|
12
|
-
def initialize(object_id:,
|
10
|
+
def initialize(object_id:, time:, random_int:)
|
13
11
|
@object_id = object_id
|
14
|
-
@host_id = host_id
|
15
12
|
@time = time
|
16
|
-
@
|
17
|
-
@counter = counter
|
13
|
+
@random_int = random_int
|
18
14
|
end
|
19
15
|
|
20
16
|
def object
|
@@ -23,23 +19,19 @@ class PropertybaseId
|
|
23
19
|
|
24
20
|
def to_s
|
25
21
|
@_string ||= begin
|
26
|
-
object_str = format_number(@object_id,
|
27
|
-
|
28
|
-
|
29
|
-
process_str = format_number(@process_id, 2)
|
30
|
-
counter_str = format_number(@counter, 5)
|
22
|
+
object_str = format_number(@object_id, 2)
|
23
|
+
time_str = format_number(@time, 7)
|
24
|
+
random_str = format_number(@random_int, 6)
|
31
25
|
|
32
|
-
"#{object_str}#{
|
26
|
+
"#{object_str}#{time_str}#{random_str}"
|
33
27
|
end
|
34
28
|
end
|
35
29
|
|
36
30
|
def ==(o)
|
37
31
|
self.class == o.class &&
|
38
32
|
self.object_id == o.object_id &&
|
39
|
-
self.host_id == o.host_id &&
|
40
|
-
self.process_id == o.process_id &&
|
41
33
|
self.time == o.time &&
|
42
|
-
self.
|
34
|
+
self.random_int == o.random_int
|
43
35
|
end
|
44
36
|
|
45
37
|
alias_method :eql?, :==
|
@@ -47,10 +39,8 @@ class PropertybaseId
|
|
47
39
|
def hash
|
48
40
|
[
|
49
41
|
object_id,
|
50
|
-
host_id,
|
51
42
|
time,
|
52
|
-
|
53
|
-
counter,
|
43
|
+
random_int,
|
54
44
|
].hash
|
55
45
|
end
|
56
46
|
|
@@ -61,21 +51,19 @@ class PropertybaseId
|
|
61
51
|
def self.parse(input_id)
|
62
52
|
raise ArgumentError, "invalid length (#{input_id.size})" if input_id.size != max_length
|
63
53
|
|
64
|
-
_, object_id,
|
54
|
+
_, object_id, time, random_str = input_id.match(/(\w{2})(\w{7})(\w{6})/).to_a
|
65
55
|
|
66
56
|
team_from_object_id(object_id.to_i(36))
|
67
57
|
|
68
58
|
new(
|
69
59
|
object_id: object_id.to_i(36),
|
70
|
-
host_id: host_id.to_i(36),
|
71
60
|
time: time.to_i(36),
|
72
|
-
|
73
|
-
counter: counter.to_i(36),
|
61
|
+
random_int: random_str.to_i(36),
|
74
62
|
)
|
75
63
|
end
|
76
64
|
|
77
65
|
def self.max_length
|
78
|
-
|
66
|
+
15
|
79
67
|
end
|
80
68
|
|
81
69
|
def self.max_value(digits = max_length)
|
@@ -1,23 +1,15 @@
|
|
1
1
|
require "digest/sha1"
|
2
2
|
require "socket"
|
3
|
+
require "securerandom"
|
3
4
|
|
4
5
|
class PropertybaseId
|
5
6
|
class Generator
|
6
|
-
def initialize
|
7
|
-
@counter = 0
|
8
|
-
@mutex = Mutex.new
|
9
|
-
end
|
10
|
-
|
11
7
|
def generate(object: )
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
process_id: process_id,
|
18
|
-
counter: next_counter
|
19
|
-
)
|
20
|
-
end
|
8
|
+
PropertybaseId.new(
|
9
|
+
object_id: pb_object_id(object),
|
10
|
+
time: ::Time.now.to_i,
|
11
|
+
random_int: random_32
|
12
|
+
)
|
21
13
|
end
|
22
14
|
|
23
15
|
private
|
@@ -32,6 +24,10 @@ class PropertybaseId
|
|
32
24
|
@_host_id ||= Digest::SHA1.hexdigest(Socket.gethostname).to_i(16) % PropertybaseId.max_value(2)
|
33
25
|
end
|
34
26
|
|
27
|
+
def random_32
|
28
|
+
SecureRandom::random_number("zzzzzz".to_i(36) + 1)
|
29
|
+
end
|
30
|
+
|
35
31
|
def next_counter
|
36
32
|
@counter = (@counter + 1) % PropertybaseId.max_value(5)
|
37
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: propertybase_id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leif Gensert
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
111
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.
|
112
|
+
rubygems_version: 2.5.1
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: Gem for creating Propertybase compatible IDs
|