ruuid 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/ruuid/generator.rb +6 -10
- data/lib/ruuid/uuid.rb +10 -14
- data/lib/ruuid/version.rb +1 -1
- data/lib/ruuid.rb +0 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e771cd338893fc6ba98871678208daffbac1d5c4
|
4
|
+
data.tar.gz: 8383b56ae6a40be9be60fa9655177a53ca551b8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67467a1ddabc1f10de041011c4cb9529776ea312f4eda91691e55d5a7f8463197ddaa798c181828ab653f919d5268455f6c0170ff1824a63af4fa24b4791f9e6
|
7
|
+
data.tar.gz: c711cb679f5e90c59c3d2ee3bcf414e00f06559e11358c6cdde09806d5a5478c32cc48a667a24ce5102e58538c9e39b7572a86150f4489f5559fa36fed183014
|
data/README.md
CHANGED
data/lib/ruuid/generator.rb
CHANGED
@@ -31,7 +31,12 @@ module RUUID
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def generate
|
34
|
-
|
34
|
+
raw_bytes.tap { |bytes|
|
35
|
+
# Mask version
|
36
|
+
bytes[6] = (bytes[6] & 0x0f) | (version << 4)
|
37
|
+
# Mask variant
|
38
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80
|
39
|
+
}.collect(&:chr).join
|
35
40
|
end
|
36
41
|
|
37
42
|
private
|
@@ -42,14 +47,5 @@ module RUUID
|
|
42
47
|
end
|
43
48
|
source.call.bytes
|
44
49
|
end
|
45
|
-
|
46
|
-
def masked_bytes
|
47
|
-
raw_bytes.tap { |bytes|
|
48
|
-
# Mask version
|
49
|
-
bytes[6] = (bytes[6] & 0x0f) | (version << 4)
|
50
|
-
# Mask variant
|
51
|
-
bytes[8] = (bytes[8] & 0x3f) | 0x80
|
52
|
-
}.collect(&:chr).join
|
53
|
-
end
|
54
50
|
end # Generator
|
55
51
|
end # RUUID
|
data/lib/ruuid/uuid.rb
CHANGED
@@ -2,24 +2,15 @@ module RUUID
|
|
2
2
|
class UUID
|
3
3
|
include Comparable
|
4
4
|
|
5
|
-
# @private
|
6
|
-
def self.from_data(data)
|
7
|
-
uuid = allocate
|
8
|
-
uuid.instance_variable_set :@data, data.dup.freeze
|
9
|
-
uuid.validate
|
10
|
-
uuid
|
11
|
-
end
|
12
|
-
|
13
5
|
def self.parse(string)
|
14
|
-
|
6
|
+
new(Parser.parse(string))
|
15
7
|
end
|
16
8
|
|
17
|
-
|
18
|
-
|
19
|
-
|
9
|
+
def initialize(data = RUUID.default_generator.generate)
|
10
|
+
@data = normalize(data)
|
11
|
+
validate
|
20
12
|
end
|
21
13
|
|
22
|
-
# @private
|
23
14
|
attr_reader :data
|
24
15
|
|
25
16
|
def to_s(format = RUUID.default_format)
|
@@ -70,7 +61,8 @@ module RUUID
|
|
70
61
|
data.bytes[6] >> 4
|
71
62
|
end
|
72
63
|
|
73
|
-
|
64
|
+
private
|
65
|
+
|
74
66
|
def validate
|
75
67
|
unless data.length == 16
|
76
68
|
raise InvalidUUIDError, 'Invalid UUID length'
|
@@ -80,5 +72,9 @@ module RUUID
|
|
80
72
|
raise InvalidUUIDError, 'Invalid UUID variant'
|
81
73
|
end
|
82
74
|
end
|
75
|
+
|
76
|
+
def normalize(data)
|
77
|
+
data.dup.force_encoding(Encoding::BINARY).freeze
|
78
|
+
end
|
83
79
|
end # UUID
|
84
80
|
end # RUUID
|
data/lib/ruuid/version.rb
CHANGED
data/lib/ruuid.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruuid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabe Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|