uuid64 0.0.2 → 0.0.3

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/uuid64.rb +20 -0
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7a3fb119f9ab900519a95e4291e6d352777a88e
4
- data.tar.gz: 4edec027ad47e2e6a753d14cf03f03878247eac7
3
+ metadata.gz: abed77850782ed0058707cb23146578460692167
4
+ data.tar.gz: 2789d338f33675d5fc06449e283d265a06cbfb42
5
5
  SHA512:
6
- metadata.gz: 10f5bf4ee327336ab0c2704a63dcf2b4353a5eadbb07440f40165d1e44592804c0f32718617ab78157fe13b8e27c8e9c7ecc5710a64042a273b7d358ff66762d
7
- data.tar.gz: 137c97f76221228775e9349259b65a6dea05486f1e8250030a21db461bfd3f34ae01d71dcbe7a7d098c7cf77a02774ee9025498cf38f7dffc415793494cccbcf
6
+ metadata.gz: 646651260e6a2270498894fc339164e5555f2af4676b5a3e85cd8fcc4a821105cd8ded35e707f24e28e3d124bedfd6131cfdc69dba8697b0fff97afd3d3cd511
7
+ data.tar.gz: 0137a16954ed78e934654b5593b8c68d1f602924c04374e5dfeb4ec0faf8b75094b2a1624c1353a9fcfed453741442bf2804dbc1e4a1f1d2c88117f28873a69f
data/lib/uuid64.rb CHANGED
@@ -1,6 +1,26 @@
1
1
  require 'securerandom'
2
+ require 'socket'
3
+ require 'digest'
2
4
  module SecureRandom
3
5
  def SecureRandom.uuid64
4
6
  [[SecureRandom.uuid.gsub(/-/, '')].pack('H*')].pack('m').gsub(/==/,'').gsub(/\n/,'')
5
7
  end
8
+ def SecureRandom.mongo_id
9
+ if @mongo_init.nil?
10
+ @mongo_init = true
11
+ @mongo_host = Digest::SHA2.hexdigest(Socket.gethostname)[0..5].freeze
12
+ @mongo_pid = Process.pid.to_s(16)[0..3].rjust(4, '0')
13
+ @mongo_inc = 0
14
+ else
15
+ @mongo_inc += 1
16
+ end
17
+
18
+ Time.now.to_i.to_s(16)[0..15].rjust(8, '0')[0..7] +
19
+ @mongo_host +
20
+ @mongo_pid +
21
+ @mongo_inc.to_s(16).rjust(6, '0')[0..5]
22
+ end
23
+ def SecureRandom.mongo_id64
24
+ [[SecureRandom.mongo_id].pack('H*')].pack('m').gsub(/\n/,'')
25
+ end
6
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uuid64
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - HeckPsi Lab
@@ -10,7 +10,7 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2016-05-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Generate a 64-bit encoded uuid in Ruby with length of 22.
13
+ description: This is a library generating unique id in short pattern.
14
14
  email: business@heckpsi.com
15
15
  executables: []
16
16
  extensions: []
@@ -40,6 +40,6 @@ rubyforge_project:
40
40
  rubygems_version: 2.6.1
41
41
  signing_key:
42
42
  specification_version: 4
43
- summary: Generate a 64-bit encoded uuid in Ruby with length of 22.
43
+ summary: This is a library generating unique id in short pattern.
44
44
  test_files: []
45
45
  has_rdoc: