youyouaidi 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -6
- data/lib/kernel_patch.rb +3 -1
- data/lib/youyouaidi/version.rb +1 -1
- data/spec/kernel_patch_spec.rb +14 -0
- data/spec/spec_helper.rb +5 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dc034244f89c5e008ac157a3623fee8c410506a
|
4
|
+
data.tar.gz: df6894a97327c5a0947d143a9c367e0901ab5261
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dddadf28922905d8c8a1797add44e48971e046354fc74031ccacecdacec9ab785e97c9703eee06579474a454770d12b25e4b31ad374c905958acbd194a0d02d
|
7
|
+
data.tar.gz: 7afcc05faff44845fd8a5b844660dd4f714ddfd475153d7e47de3643c5d31388f896e248e710f0f155e173b3efc19a88576aca17eb254d1ffff8c0e0d898f567
|
data/README.md
CHANGED
@@ -14,12 +14,11 @@ For UUID generation, the `SecureRandom.uuid` method is used which generates vali
|
|
14
14
|
|
15
15
|
This is what a valid, random (version 4) UUID looks like:
|
16
16
|
```
|
17
|
-
# chars in group: 8 | 4 | 4 | 4 | 12
|
18
|
-
▼ ▼ ▼ ▼ ▼
|
19
|
-
caed3f49-b0ca-454b-adf8-5ee2a1764759
|
20
|
-
▲ ▲
|
21
17
|
version either 8, 9
|
22
|
-
number
|
18
|
+
number a, or b
|
19
|
+
▼ ▼
|
20
|
+
caed3f49-b0ca-454b-adf8-5ee2a1764759
|
21
|
+
# chars in group: 8 | 4 | 4 | 4 | 12
|
23
22
|
```
|
24
23
|
As shown, the first digit of the third group indicates the UUID version.
|
25
24
|
The first digit of the fourth group always has to be one of either `8`, `9`, `a`, or `b`.
|
@@ -43,6 +42,9 @@ Or install it yourself as:
|
|
43
42
|
|
44
43
|
## Usage
|
45
44
|
|
45
|
+
For usability, `UUID(...)` is patched into the kernel as a shorthand call to `Youyouaidi::UUID.parse(...)`.
|
46
|
+
Also, `UUID` is patched as a reference for the class `Youyouid::UUID`.
|
47
|
+
|
46
48
|
### Initializing UUIDs
|
47
49
|
|
48
50
|
```ruby
|
@@ -64,11 +66,15 @@ new_uuid = UUID() # generates a random UUID version 4 using the SecureRa
|
|
64
66
|
|
65
67
|
### Validity check and conversions
|
66
68
|
|
69
|
+
The validity check `UUID.valid? uuid_string` checks, if UUID contains exactly 32 hexadecimal characters which are divided by four dashes ('-') into five groups of sizes 8, 4, 4, 4, and 12.
|
70
|
+
Also, it validates that the first character of the fourth group is either a `8`, `9`, an `a`, or a `b`.
|
71
|
+
|
67
72
|
```ruby
|
68
73
|
uuid_string = '550e8400-e29b-41d4-a716-446655440000' # A valid UUID in string format
|
69
74
|
uuid = UUID uuid_string
|
70
75
|
|
71
|
-
|
76
|
+
UUID.valid? uuid_string # Checks if `uuid_string' is a valid UUID, same as Youyouaidi::UUID.valid? uuid_string
|
77
|
+
# => true
|
72
78
|
|
73
79
|
uuid.to_s # Returns the string representation of the UUID object
|
74
80
|
# => '550e8400-e29b-41d4-a716-446655440000'
|
data/lib/kernel_patch.rb
CHANGED
data/lib/youyouaidi/version.rb
CHANGED
data/spec/kernel_patch_spec.rb
CHANGED
@@ -35,4 +35,18 @@ describe Kernel do
|
|
35
35
|
it { should raise_error Youyouaidi::InvalidUUIDError }
|
36
36
|
end
|
37
37
|
end
|
38
|
+
|
39
|
+
describe 'UUID class behaves as an alias for Youyouaidi::UUID' do
|
40
|
+
describe '.new' do
|
41
|
+
let(:param) { '' }
|
42
|
+
let(:action) { UUID.new param }
|
43
|
+
subject { action }
|
44
|
+
|
45
|
+
context 'without a param' do
|
46
|
+
let(:action) { UUID.new }
|
47
|
+
subject { action }
|
48
|
+
it { should be_a Youyouaidi::UUID }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
38
52
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,8 +4,11 @@ require 'bundler'
|
|
4
4
|
Bundler.require
|
5
5
|
|
6
6
|
# Code coverage statistics at coveralls.io: https://coveralls.io/r/nicolas-fricke/youyouaidi
|
7
|
-
|
8
|
-
|
7
|
+
# Generate coverage reports only when using MRI, see: https://github.com/lemurheavy/coveralls-public/issues/144
|
8
|
+
if ENV['TRAVIS'] && ENV['COVERALLS'] && RUBY_ENGINE == 'ruby'
|
9
|
+
require 'coveralls'
|
10
|
+
Coveralls.wear!
|
11
|
+
end
|
9
12
|
|
10
13
|
require 'youyouaidi'
|
11
14
|
|