rubyflake 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubyflake.rb +13 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fcfe3d104d7112ba3190d507096b49a7a22c0ff
|
4
|
+
data.tar.gz: cf3774eab601a45a726fecbc88440e364284c050
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d6fe658a5dac93dd573a5a58b77f7bf843dd0bb7640dd3f6ef24c86fd225c9175d8332e24f0fd2a45c1b9dc2ea8ea22cfd11a2f450e60c936f3ce2ec0083c11
|
7
|
+
data.tar.gz: c9235b923da1c65581b127a636d1712854f76f6b5a8dc8567588f2261a3cb094bae244c93e2ac748f3d8d6f8c27867b3a5eeeea9705ff24fa5c0d7580f258739
|
data/lib/rubyflake.rb
CHANGED
@@ -4,7 +4,7 @@ class Rubyflake
|
|
4
4
|
|
5
5
|
FLAKE_TIMESTAMP_LENGTH = 41
|
6
6
|
|
7
|
-
|
7
|
+
FLAKE_RANDOM_MAX = 0b1111111111111111111111111
|
8
8
|
FLAKE_TIMESTAMP_SHIFT = 23
|
9
9
|
|
10
10
|
def initialize(epoch = EPOCH)
|
@@ -16,7 +16,7 @@ class Rubyflake
|
|
16
16
|
milliseconds = ((Time.now().to_f - @epoch) * 1000).to_i
|
17
17
|
|
18
18
|
# Generate 23 random bits.
|
19
|
-
random_bits = Random.new.rand(0..Rubyflake::
|
19
|
+
random_bits = Random.new.rand(0..Rubyflake::FLAKE_RANDOM_MAX)
|
20
20
|
|
21
21
|
# Shift our timestamp over 23 bits to make room for the random bits,
|
22
22
|
# and then add the two together.
|
@@ -24,10 +24,20 @@ class Rubyflake
|
|
24
24
|
|
25
25
|
end
|
26
26
|
|
27
|
+
# Extract the time from an ID.
|
28
|
+
#
|
29
|
+
def time(id)
|
30
|
+
Time.at(((id >> Rubyflake::FLAKE_TIMESTAMP_SHIFT) + @epoch) / 1000)
|
31
|
+
end
|
32
|
+
|
27
33
|
class << self
|
28
34
|
def generate(epoch = Rubyflake::EPOCH)
|
29
35
|
Rubyflake.new(epoch).generate()
|
30
36
|
end
|
37
|
+
|
38
|
+
def time(id, epoch = Rubyflake::EPOCH)
|
39
|
+
Rubyflake.new(epoch).time(id)
|
40
|
+
end
|
31
41
|
end
|
32
42
|
|
33
|
-
end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyflake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Hogan
|
@@ -29,17 +29,17 @@ require_paths:
|
|
29
29
|
- lib
|
30
30
|
required_ruby_version: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - '>='
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '0'
|
35
35
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- -
|
37
|
+
- - '>='
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
40
|
requirements: []
|
41
41
|
rubyforge_project:
|
42
|
-
rubygems_version: 2.2.
|
42
|
+
rubygems_version: 2.2.1
|
43
43
|
signing_key:
|
44
44
|
specification_version: 4
|
45
45
|
summary: Simple, distributed 64-bit unique ID generation.
|