active_uxid 5.0.1 → 5.0.2

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: 67a19efe8695bb9f424821530f2f57347bc95b23
4
- data.tar.gz: bac7a5f7775e4b09247bf7ac5ee85a53609ea452
3
+ metadata.gz: ea6cf79cc6bb9d309af2a2c882680a5896cc72b3
4
+ data.tar.gz: 9a13d21b1a1f3105f17a9744a5101c1d78938512
5
5
  SHA512:
6
- metadata.gz: 6ea7ff817c90897474b91d8899e0a3c642f93413903d2973a95939d99c1732094c3fe1feb61fa28c76c2e6873bb9b60d95d589c6a6af3c4fc8889f37a9644f49
7
- data.tar.gz: 1802c40c533c51977cdbece215c2cd44eb4dd04a31c95397826c8480551027dc62feceaada52495a8b2e4ea5b9a381d1ca782ca5af390731985e95164dd39d7f
6
+ metadata.gz: c06be4e3cc8faaef59d10eb215f8fea3d61faab74880f31b31bb609d1c8af52200fc3e8ae8492ce90b3e90ed1bf85cceaa191d1fdafdf9ba0402f8fb81efde44
7
+ data.tar.gz: 7da641ce0d21cb341f45094ef4f3ae29feb4c8165e95421d2960d65207d048d10b940aadc84c2d6f601093d98e86971dec47c090e81a8cf649e5711548c1c808
@@ -1,20 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ActiveUxid
4
- class Base
3
+ class ActiveUxid::Base
5
4
 
6
- def initialize
7
- @config = ActiveUxid.configuration
8
- end
9
-
10
- ActiveUxid.configuration.instance_variables.each do |setting|
11
- setting = setting.to_s.tr(':@', '')
12
- define_method(setting) { @config.send(setting) }
13
- end
5
+ def initialize
6
+ @config = ActiveUxid.configuration
7
+ end
14
8
 
15
- def encoding_base
16
- encoding_chars.length
17
- end
9
+ ActiveUxid.configuration.instance_variables.each do |setting|
10
+ setting = setting.to_s.tr(':@', '')
11
+ define_method(setting) { @config.send(setting) }
12
+ end
18
13
 
14
+ def encoding_base
15
+ encoding_chars.length
19
16
  end
17
+
20
18
  end
@@ -1,59 +1,57 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ActiveUxid
4
- class Hash < ActiveUxid::Base
3
+ class ActiveUxid::Hash < ActiveUxid::Base
5
4
 
6
- def initialize(id)
7
- @id = id
8
- super()
9
- end
10
-
11
- def self.encode(id)
12
- klass = new(id)
13
- klass.encode_uxid
14
- end
5
+ def initialize(id)
6
+ @id = id
7
+ super()
8
+ end
15
9
 
16
- def self.decode(id)
17
- klass = new(id)
18
- klass.decode_uxid
19
- end
10
+ def self.encode(id)
11
+ klass = new(id)
12
+ klass.encode_uxid
13
+ end
20
14
 
21
- def encode_uxid
22
- uxid_encode_chars((@id + encoding_salt) << encoding_length)
23
- end
15
+ def self.decode(id)
16
+ klass = new(id)
17
+ klass.decode_uxid
18
+ end
24
19
 
25
- def decode_uxid
26
- (uxid_decode_chars(@id) >> encoding_length) - encoding_salt
27
- end
20
+ def encode_uxid
21
+ uxid_encode_chars((@id + encoding_salt) << encoding_length)
22
+ end
28
23
 
29
- def uxid_encode_chars(id)
30
- return '0' if id.zero?
31
- return nil if id.negative?
24
+ def decode_uxid
25
+ (uxid_decode_chars(@id) >> encoding_length) - encoding_salt
26
+ end
32
27
 
33
- str = ''
28
+ def uxid_encode_chars(id)
29
+ return '0' if id.zero?
30
+ return nil if id.negative?
34
31
 
35
- while id.positive?
36
- str = "#{encoding_chars[id % encoding_base]}#{str}"
37
- id /= encoding_base
38
- end
32
+ str = ''
39
33
 
40
- str
34
+ while id.positive?
35
+ str = "#{encoding_chars[id % encoding_base]}#{str}"
36
+ id /= encoding_base
41
37
  end
42
38
 
43
- def uxid_decode_chars(id)
44
- pos = 0
45
- num = 0
46
- len = id.length
47
- max = len - 1
39
+ str
40
+ end
48
41
 
49
- while pos < len
50
- pow = encoding_base**(max - pos)
51
- num += encoding_chars.index(id[pos]) * pow
52
- pos += 1
53
- end
42
+ def uxid_decode_chars(id)
43
+ pos = 0
44
+ num = 0
45
+ len = id.length
46
+ max = len - 1
54
47
 
55
- num
48
+ while pos < len
49
+ pow = encoding_base**(max - pos)
50
+ num += encoding_chars.index(id[pos]) * pow
51
+ pos += 1
56
52
  end
57
53
 
54
+ num
58
55
  end
56
+
59
57
  end
@@ -1,36 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module ActiveUxid
4
- class Ulid < ActiveUxid::Base
3
+ class ActiveUxid::Ulid < ActiveUxid::Base
5
4
 
6
- def self.encode
7
- klass = new
8
- klass.uxid_encode
9
- end
10
-
11
- def uxid_encode
12
- (1..encoding_length).reduce('') do |str, num|
13
- shift = 128 - 5 * num
14
- "#{str}#{encoding_chars[(uxid_octect >> shift) & 0x1f]}"
15
- end
16
- end
5
+ def self.encode
6
+ klass = new
7
+ klass.uxid_encode
8
+ end
17
9
 
18
- def uxid_bytes
19
- "#{uxid_unixtime_48bit}#{SecureRandom.random_bytes(10)}"
10
+ def uxid_encode
11
+ (1..encoding_length).reduce('') do |str, num|
12
+ shift = 128 - 5 * num
13
+ "#{str}#{encoding_chars[(uxid_octect >> shift) & 0x1f]}"
20
14
  end
15
+ end
21
16
 
22
- def uxid_octect
23
- (hi, lo) = uxid_bytes.unpack('Q>Q>')
24
- (hi << 64) | lo
25
- end
17
+ def uxid_bytes
18
+ "#{uxid_unixtime_48bit}#{SecureRandom.random_bytes(10)}"
19
+ end
26
20
 
27
- def uxid_unixtime_flex
28
- (Time.current.to_f * 10_000).to_i
29
- end
21
+ def uxid_octect
22
+ (hi, lo) = uxid_bytes.unpack('Q>Q>')
23
+ (hi << 64) | lo
24
+ end
30
25
 
31
- def uxid_unixtime_48bit
32
- [uxid_unixtime_flex].pack('Q>')[2..-1]
33
- end
26
+ def uxid_unixtime_flex
27
+ (Time.current.to_f * 10_000).to_i
28
+ end
34
29
 
30
+ def uxid_unixtime_48bit
31
+ [uxid_unixtime_flex].pack('Q>')[2..-1]
35
32
  end
33
+
36
34
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRegulation
4
- VERSION ||= '5.0.1'
4
+ VERSION ||= '5.0.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_uxid
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.1
4
+ version: 5.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez