propertybase_id 0.5.0 → 0.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac838b018ad983510c03dce597ba9ccfac7dcf71
4
- data.tar.gz: c317f3ccbbca7711dbeac609de19b0ee3b4120f9
3
+ metadata.gz: 4d0822383ba08e57c55f45eb116a0577b49bccff
4
+ data.tar.gz: f672a9f1b0fa2a7ee724bb7a880079af0b026cf6
5
5
  SHA512:
6
- metadata.gz: dc73eac7d74ac9d07ec85d2a170cb468824608df7c12e24a99579f1bd343df8c51ea6248fa2ed6dc0d40c9a9e636068ae90e487739434e98bc8965f921404e81
7
- data.tar.gz: 57d96e6e466ba87b9e4a3f32f198a91b14e0fa8a9db594ce7bb94ddb6d12bfabf06183d4ff8cd9cedd38a6be1aa35f771ba3ac767f867c656b84c8a603c44469
6
+ metadata.gz: 5e9940e69dce5eac1844f63fdaa9ee50422be5e107da2d9f5220cbd1bee73a94129f11d0ca1d30a17df932e485afbaaaf125715dd5c81b95611b813e99c1bc3f
7
+ data.tar.gz: 8b040542ed0fccbdda7325c2e8a3966c8bf67e06bea2afe9342dabc6ddcca32fcf51b6f221193caf38bd49fa9cebc5debc9bd8a4ad40d5c5732f4d4250bb364b
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ /vendor/bundle
data/.travis.yml CHANGED
@@ -2,8 +2,9 @@ language: ruby
2
2
  cache: bundler
3
3
  bundler_args: --without documentation production
4
4
  rvm:
5
- - 2.1.5
6
- - 2.2.1
5
+ - 2.1.8
6
+ - 2.2.4
7
+ - 2.3.0
7
8
  - rbx
8
9
  - ruby-head
9
10
  - jruby-head
@@ -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 :process_id
10
- attr_reader :counter
8
+ attr_reader :random_int
11
9
 
12
- def initialize(object_id:, host_id:, time:, process_id:, counter:)
10
+ def initialize(object_id:, time:, random_int:)
13
11
  @object_id = object_id
14
- @host_id = host_id
15
12
  @time = time
16
- @process_id = process_id
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, 3)
27
- host_str = format_number(@host_id, 2)
28
- time_str = format_number(@time, 6)
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}#{host_str}#{time_str}#{process_str}#{counter_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.counter == o.counter
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
- process_id,
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, host_id, time, process_id, counter = input_id.match(/(\w{3})(\w{2})(\w{6})(\w{2})(\w{5})/).to_a
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
- process_id: process_id.to_i(36),
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
- 18
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
- @mutex.synchronize do
13
- PropertybaseId.new(
14
- object_id: pb_object_id(object),
15
- host_id: host_id,
16
- time: ::Time.now.to_i,
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
@@ -1,3 +1,3 @@
1
1
  class PropertybaseId
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  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.5.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: 2015-05-31 00:00:00.000000000 Z
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.4.5
112
+ rubygems_version: 2.5.1
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: Gem for creating Propertybase compatible IDs