youyouaidi-revised 1.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +16 -2
- data/lib/{youyouaidi → youyouaidi-revised}/converter.rb +0 -0
- data/lib/{youyouaidi → youyouaidi-revised}/invalid_uuid.rb +0 -0
- data/lib/{youyouaidi → youyouaidi-revised}/uuid.rb +0 -0
- data/lib/{youyouaidi → youyouaidi-revised}/version.rb +1 -1
- data/lib/youyouaidi-revised.rb +10 -0
- metadata +8 -23
- data/.gitignore +0 -17
- data/.rspec +0 -2
- data/.rubocop.yml +0 -80
- data/.travis.yml +0 -9
- data/Gemfile +0 -15
- data/Rakefile +0 -7
- data/lib/youyouaidi.rb +0 -10
- data/spec/kernel_patch_spec.rb +0 -11
- data/spec/spec_helper.rb +0 -39
- data/spec/youyouaidi/converter_spec.rb +0 -103
- data/spec/youyouaidi/uuid_spec.rb +0 -261
- data/youyouaidi-revised.gemspec +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f102885d1adab818d4405f3e8264306b83a5193de69f6ccce4c5587ed2a6033b
|
4
|
+
data.tar.gz: 92bdd761eda313a8778f82d292dd15300033b4cd6b0ad0e64d22f381d7bb33a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b9d453d959c0f4487fe4262b6914fc6d2dab2e0bd9504947f2aa8e0b8cf5471508052ef5c1c455866d99f85febb027d600cb53e35d3aa944ec029f8c54b8d97
|
7
|
+
data.tar.gz: c4e21eb48eff7fea9be4641fb18715e70d716d0220fb0a65aec559d197dd9244d560bad3406d8b2463668ccaf43704359adec14d619d9e8bb775d46763ccda5d
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -41,18 +41,27 @@ Or install it yourself as:
|
|
41
41
|
## Usage
|
42
42
|
|
43
43
|
`UUID(...)` **was** patched in the kernel. Not anymore. We don't patch the kernel unless we have no other choice.
|
44
|
+
This means this gem is not backwards compatible.
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
require 'youyouaidi'
|
48
|
+
|
49
|
+
# Use youyouaidi
|
50
|
+
|
51
|
+
```
|
44
52
|
|
45
53
|
### Initializing UUIDs
|
46
54
|
|
47
55
|
```ruby
|
56
|
+
|
48
57
|
uuid_string = '550e8400-e29b-41d4-a716-446655440000' # A valid UUID in string format, has exactly 32 hexadecimal characters in 5 groups
|
49
58
|
uuid_short = '2AuYQJcZeiIeCymkJ7tzTW' # Same UUID in its short format, has exactly 22 characters of [0-9a-zA-Z]
|
50
59
|
|
51
|
-
uuid = Youyouaidi::UUID uuid_string # creates new Youyouaidi::UUID object
|
60
|
+
uuid = Youyouaidi::UUID.parse uuid_string # creates new Youyouaidi::UUID object
|
52
61
|
# => #<Youyouaidi::UUID:0x000001021f2590 @converter=Youyouaidi::Converter, @uuid="550e8400-e29b-41d4-a716-446655440000">
|
53
62
|
|
54
63
|
# Alternatively a short UUID can be passed:
|
55
|
-
uuid = Youyouaidi::UUID uuid_short # creates similar Youyouaidi::UUID object
|
64
|
+
uuid = Youyouaidi::UUID.parse uuid_short # creates similar Youyouaidi::UUID object
|
56
65
|
# => #<Youyouaidi::UUID:0x00000102201b80 @converter=Youyouaidi::Converter, @uuid="550e8400-e29b-41d4-a716-446655440000">
|
57
66
|
|
58
67
|
# To generate a new random UUID simply do not pass a parameter:
|
@@ -109,3 +118,8 @@ uuid === uuid_string # Comparing a UUID object and its string representation wit
|
|
109
118
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
110
119
|
4. Push to the branch (`git push origin my-new-feature`)
|
111
120
|
5. Create new Pull Request
|
121
|
+
|
122
|
+
|
123
|
+
## Build gem
|
124
|
+
1. gem build youyouaidi-revised.gemspec
|
125
|
+
2. gem install ./youyouaidi-revised-x.x.gem
|
File without changes
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: youyouaidi-revised
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolas Fricke
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-11-
|
12
|
+
date: 2021-11-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -47,24 +47,13 @@ executables: []
|
|
47
47
|
extensions: []
|
48
48
|
extra_rdoc_files: []
|
49
49
|
files:
|
50
|
-
- ".gitignore"
|
51
|
-
- ".rspec"
|
52
|
-
- ".rubocop.yml"
|
53
|
-
- ".travis.yml"
|
54
|
-
- Gemfile
|
55
50
|
- LICENSE.txt
|
56
51
|
- README.md
|
57
|
-
-
|
58
|
-
- lib/youyouaidi.rb
|
59
|
-
- lib/youyouaidi/
|
60
|
-
- lib/youyouaidi/
|
61
|
-
- lib/youyouaidi/
|
62
|
-
- lib/youyouaidi/version.rb
|
63
|
-
- spec/kernel_patch_spec.rb
|
64
|
-
- spec/spec_helper.rb
|
65
|
-
- spec/youyouaidi/converter_spec.rb
|
66
|
-
- spec/youyouaidi/uuid_spec.rb
|
67
|
-
- youyouaidi-revised.gemspec
|
52
|
+
- lib/youyouaidi-revised.rb
|
53
|
+
- lib/youyouaidi-revised/converter.rb
|
54
|
+
- lib/youyouaidi-revised/invalid_uuid.rb
|
55
|
+
- lib/youyouaidi-revised/uuid.rb
|
56
|
+
- lib/youyouaidi-revised/version.rb
|
68
57
|
homepage: https://github.com/LoranKloeze/youyouaidi-revised
|
69
58
|
licenses:
|
70
59
|
- MIT
|
@@ -88,8 +77,4 @@ rubygems_version: 3.1.6
|
|
88
77
|
signing_key:
|
89
78
|
specification_version: 4
|
90
79
|
summary: UUID class
|
91
|
-
test_files:
|
92
|
-
- spec/kernel_patch_spec.rb
|
93
|
-
- spec/spec_helper.rb
|
94
|
-
- spec/youyouaidi/converter_spec.rb
|
95
|
-
- spec/youyouaidi/uuid_spec.rb
|
80
|
+
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
# .rubocop.yml
|
2
|
-
AllCops:
|
3
|
-
TargetRubyVersion: 2.7
|
4
|
-
|
5
|
-
Style/Documentation:
|
6
|
-
Enabled: false
|
7
|
-
|
8
|
-
|
9
|
-
Gemspec/DateAssignment: # (new in 1.10)
|
10
|
-
Enabled: true
|
11
|
-
Layout/LineEndStringConcatenationIndentation: # (new in 1.18)
|
12
|
-
Enabled: true
|
13
|
-
Layout/SpaceBeforeBrackets: # (new in 1.7)
|
14
|
-
Enabled: true
|
15
|
-
Lint/AmbiguousAssignment: # (new in 1.7)
|
16
|
-
Enabled: true
|
17
|
-
Lint/DeprecatedConstants: # (new in 1.8)
|
18
|
-
Enabled: true
|
19
|
-
Lint/DuplicateBranch: # (new in 1.3)
|
20
|
-
Enabled: true
|
21
|
-
Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1)
|
22
|
-
Enabled: true
|
23
|
-
Lint/EmptyBlock: # (new in 1.1)
|
24
|
-
Enabled: true
|
25
|
-
Lint/EmptyClass: # (new in 1.3)
|
26
|
-
Enabled: true
|
27
|
-
Lint/EmptyInPattern: # (new in 1.16)
|
28
|
-
Enabled: true
|
29
|
-
Lint/LambdaWithoutLiteralBlock: # (new in 1.8)
|
30
|
-
Enabled: true
|
31
|
-
Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
|
32
|
-
Enabled: true
|
33
|
-
Lint/NumberedParameterAssignment: # (new in 1.9)
|
34
|
-
Enabled: true
|
35
|
-
Lint/OrAssignmentToConstant: # (new in 1.9)
|
36
|
-
Enabled: true
|
37
|
-
Lint/RedundantDirGlobSort: # (new in 1.8)
|
38
|
-
Enabled: true
|
39
|
-
Lint/SymbolConversion: # (new in 1.9)
|
40
|
-
Enabled: true
|
41
|
-
Lint/ToEnumArguments: # (new in 1.1)
|
42
|
-
Enabled: true
|
43
|
-
Lint/TripleQuotes: # (new in 1.9)
|
44
|
-
Enabled: true
|
45
|
-
Lint/UnexpectedBlockArity: # (new in 1.5)
|
46
|
-
Enabled: true
|
47
|
-
Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
|
48
|
-
Enabled: true
|
49
|
-
Naming/InclusiveLanguage: # (new in 1.18)
|
50
|
-
Enabled: true
|
51
|
-
Style/ArgumentsForwarding: # (new in 1.1)
|
52
|
-
Enabled: true
|
53
|
-
Style/CollectionCompact: # (new in 1.2)
|
54
|
-
Enabled: true
|
55
|
-
Style/DocumentDynamicEvalDefinition: # (new in 1.1)
|
56
|
-
Enabled: true
|
57
|
-
Style/EndlessMethod: # (new in 1.8)
|
58
|
-
Enabled: true
|
59
|
-
Style/HashConversion: # (new in 1.10)
|
60
|
-
Enabled: true
|
61
|
-
Style/HashExcept: # (new in 1.7)
|
62
|
-
Enabled: true
|
63
|
-
Style/IfWithBooleanLiteralBranches: # (new in 1.9)
|
64
|
-
Enabled: true
|
65
|
-
Style/InPatternThen: # (new in 1.16)
|
66
|
-
Enabled: true
|
67
|
-
Style/MultilineInPatternThen: # (new in 1.16)
|
68
|
-
Enabled: true
|
69
|
-
Style/NegatedIfElseCondition: # (new in 1.2)
|
70
|
-
Enabled: true
|
71
|
-
Style/NilLambda: # (new in 1.3)
|
72
|
-
Enabled: true
|
73
|
-
Style/QuotedSymbols: # (new in 1.16)
|
74
|
-
Enabled: true
|
75
|
-
Style/RedundantArgument: # (new in 1.4)
|
76
|
-
Enabled: true
|
77
|
-
Style/StringChars: # (new in 1.12)
|
78
|
-
Enabled: true
|
79
|
-
Style/SwapValues: # (new in 1.1)
|
80
|
-
Enabled: true
|
data/.travis.yml
DELETED
data/Gemfile
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source 'https://rubygems.org'
|
4
|
-
|
5
|
-
group :test do
|
6
|
-
gem 'coveralls', require: false
|
7
|
-
gem 'pry'
|
8
|
-
gem 'rake', '~> 10.1'
|
9
|
-
gem 'rspec'
|
10
|
-
gem 'rspec-collection_matchers'
|
11
|
-
gem 'rspec-its'
|
12
|
-
end
|
13
|
-
|
14
|
-
# Specify your gem's dependencies in youyouaidi.gemspec
|
15
|
-
gemspec
|
data/Rakefile
DELETED
data/lib/youyouaidi.rb
DELETED
data/spec/kernel_patch_spec.rb
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rspec'
|
4
|
-
require 'rspec/its'
|
5
|
-
require 'rspec/collection_matchers'
|
6
|
-
require 'pry'
|
7
|
-
|
8
|
-
# Code coverage statistics at coveralls.io: https://coveralls.io/r/nicolas-fricke/youyouaidi
|
9
|
-
# Do not generate coverage when using Rubinius, see: https://github.com/lemurheavy/coveralls-public/issues/144
|
10
|
-
if ENV['CI'] || (defined?(:RUBY_ENGINE) && RUBY_ENGINE != 'rbx')
|
11
|
-
require 'coveralls'
|
12
|
-
Coveralls.wear! do
|
13
|
-
add_filter 'spec'
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
require 'bundler'
|
18
|
-
Bundler.require
|
19
|
-
|
20
|
-
require 'youyouaidi'
|
21
|
-
|
22
|
-
RSpec.configure do |config|
|
23
|
-
# ## Mock Framework
|
24
|
-
#
|
25
|
-
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
26
|
-
#
|
27
|
-
# config.mock_with :mocha
|
28
|
-
# config.mock_with :flexmock
|
29
|
-
# config.mock_with :rr
|
30
|
-
|
31
|
-
# Run specs in random order to surface order dependencies. If you find an
|
32
|
-
# order dependency and want to debug it, you can fix the order by providing
|
33
|
-
# the seed, which is printed after each run.
|
34
|
-
# --seed 1234
|
35
|
-
config.order = 'random'
|
36
|
-
|
37
|
-
# Raise error when using old :should expectation syntax.
|
38
|
-
# config.raise_errors_for_deprecations!
|
39
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
# rubocop:disable Metrics/BlockLength
|
6
|
-
describe Youyouaidi::Converter do
|
7
|
-
shared_examples_for 'a call that raises a Youyouaidi::InvalidUUIDError with a meaningful error message' do
|
8
|
-
describe 'raises error' do
|
9
|
-
subject { -> { action } }
|
10
|
-
it { should raise_error Youyouaidi::InvalidUUIDError }
|
11
|
-
describe 'error message' do
|
12
|
-
let(:caught_error) do
|
13
|
-
action
|
14
|
-
return nil
|
15
|
-
rescue Youyouaidi::InvalidUUIDError => e
|
16
|
-
return e
|
17
|
-
end
|
18
|
-
subject { caught_error }
|
19
|
-
it { should_not be_nil }
|
20
|
-
its(:message) { should include(*error_message_includes) }
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
let(:uuid) { Youyouaidi::UUID.new uuid_string }
|
26
|
-
let(:uuid_string) { '550e8400-e29b-41d4-a716-446655440000' }
|
27
|
-
let(:encoded_uuid) { '2AuYQJcZeiIeCymkJ7tzTW' }
|
28
|
-
|
29
|
-
uuids_with_encoding = {
|
30
|
-
'550e8400-e29b-41d4-a716-446655440000' => '2AuYQJcZeiIeCymkJ7tzTW',
|
31
|
-
'00000000-bbbb-2222-8888-000000000000' => '000001dyObGywDRlcScExy'
|
32
|
-
}
|
33
|
-
|
34
|
-
describe 'use case' do
|
35
|
-
subject { described_class.decode described_class.encode(uuid) }
|
36
|
-
|
37
|
-
it { should be_a Youyouaidi::UUID }
|
38
|
-
its(:to_s) { should eq uuid_string }
|
39
|
-
end
|
40
|
-
|
41
|
-
describe 'methods' do
|
42
|
-
describe '.encode' do
|
43
|
-
subject { described_class.encode uuid }
|
44
|
-
|
45
|
-
uuids_with_encoding.each do |valid_uuid, encoded_uuid|
|
46
|
-
context "for uuid `#{valid_uuid}'" do
|
47
|
-
let(:uuid_string) { valid_uuid }
|
48
|
-
it { should have(22).characters }
|
49
|
-
it { should eq encoded_uuid }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe '.decode' do
|
55
|
-
let(:action) { described_class.decode encoded_param }
|
56
|
-
|
57
|
-
context 'with valid param' do
|
58
|
-
subject { action }
|
59
|
-
|
60
|
-
uuids_with_encoding.each do |valid_uuid, encoded_uuid|
|
61
|
-
context "for encoded uuid `#{encoded_uuid}'" do
|
62
|
-
let(:encoded_param) { encoded_uuid }
|
63
|
-
it { should be_a Youyouaidi::UUID }
|
64
|
-
its(:to_s) { should eq valid_uuid }
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context 'with invalid param' do
|
70
|
-
subject { -> { action } }
|
71
|
-
context 'looking correct but converting to a non-valid UUID' do
|
72
|
-
let(:encoded_param) { 'qEsRTcgdJFVugbBqtaEoNf' }
|
73
|
-
let(:decoded_invalid_uuid) { '36bb9153-3a5a-1570-de9d-6faed4f1ceb0' }
|
74
|
-
let(:error_message_includes) { ["`#{encoded_param}'", "`#{decoded_invalid_uuid}'"] }
|
75
|
-
it_behaves_like 'a call that raises a Youyouaidi::InvalidUUIDError with a meaningful error message'
|
76
|
-
end
|
77
|
-
|
78
|
-
context 'with invalid characters' do
|
79
|
-
let(:invalid_char) { '_' }
|
80
|
-
let(:encoded_param) { "#{invalid_char}#{encoded_uuid[1..]}" }
|
81
|
-
let(:error_message_includes) { ["`#{encoded_param}'", "`#{invalid_char}'"] }
|
82
|
-
it_behaves_like 'a call that raises a Youyouaidi::InvalidUUIDError with a meaningful error message'
|
83
|
-
end
|
84
|
-
|
85
|
-
shared_examples_for 'a call with incorrect param string length' do
|
86
|
-
let(:error_message_includes) { ["`#{encoded_param}'", '22', encoded_param.length.to_s] }
|
87
|
-
it_behaves_like 'a call that raises a Youyouaidi::InvalidUUIDError with a meaningful error message'
|
88
|
-
end
|
89
|
-
|
90
|
-
context 'with too long encoded param' do
|
91
|
-
let(:encoded_param) { "#{encoded_uuid}abc" }
|
92
|
-
it_behaves_like 'a call with incorrect param string length'
|
93
|
-
end
|
94
|
-
|
95
|
-
context 'with too short encoded param' do
|
96
|
-
let(:encoded_param) { encoded_uuid[0..-3].to_s }
|
97
|
-
it_behaves_like 'a call with incorrect param string length'
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
# rubocop:enable Metrics/BlockLength
|
@@ -1,261 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
# rubocop:disable Metrics/BlockLength
|
6
|
-
describe Youyouaidi::UUID do
|
7
|
-
shared_examples_for 'a call that raises a Youyouaidi::InvalidUUIDError with a meaningful error message' do
|
8
|
-
describe 'raises error' do
|
9
|
-
subject { -> { action } }
|
10
|
-
it { should raise_error Youyouaidi::InvalidUUIDError }
|
11
|
-
describe 'error message' do
|
12
|
-
let(:caught_error) do
|
13
|
-
action
|
14
|
-
return nil
|
15
|
-
rescue Youyouaidi::InvalidUUIDError => e
|
16
|
-
return e
|
17
|
-
end
|
18
|
-
subject { caught_error }
|
19
|
-
it { should_not be_nil }
|
20
|
-
its(:message) { should include(*error_message_includes) }
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '.new' do
|
26
|
-
let(:param) { '' }
|
27
|
-
let(:action) { Youyouaidi::UUID.new param }
|
28
|
-
subject { -> { action } }
|
29
|
-
|
30
|
-
context 'without a param' do
|
31
|
-
let(:action) { Youyouaidi::UUID.new }
|
32
|
-
subject { action }
|
33
|
-
|
34
|
-
it { should be_a Youyouaidi::UUID }
|
35
|
-
describe 'having a valid UUID version 4' do
|
36
|
-
subject { action.to_s }
|
37
|
-
|
38
|
-
it { should be_a String }
|
39
|
-
it { should have(36).characters }
|
40
|
-
it { should match(/[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}/i) }
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'with valid uuid string' do
|
45
|
-
subject { action }
|
46
|
-
|
47
|
-
valid_uuids = %w[550e8400-e29b-41d4-a716-446655440000
|
48
|
-
00000000-bbbb-2222-8888-000000000000]
|
49
|
-
|
50
|
-
valid_uuids.each do |valid_uuid|
|
51
|
-
context "for uuid `#{valid_uuid}'" do
|
52
|
-
let(:param) { valid_uuid }
|
53
|
-
it { should be_a Youyouaidi::UUID }
|
54
|
-
its(:to_s) { should eq param }
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'with valid uuid in short format' do
|
60
|
-
let(:param) { '2AuYQJcZeiIeCymkJ7tzTW' }
|
61
|
-
let(:error_message_includes) { "`#{param}'" }
|
62
|
-
it_behaves_like 'a call that raises a Youyouaidi::InvalidUUIDError with a meaningful error message'
|
63
|
-
end
|
64
|
-
|
65
|
-
context 'with invalid uuid string' do
|
66
|
-
let(:param) { 'Kekse' }
|
67
|
-
let(:error_message_includes) { "`#{param}'" }
|
68
|
-
it_behaves_like 'a call that raises a Youyouaidi::InvalidUUIDError with a meaningful error message'
|
69
|
-
end
|
70
|
-
|
71
|
-
context 'with non-uuid-string input' do
|
72
|
-
let(:param) { 1234 }
|
73
|
-
let(:error_message_includes) { "`#{param}'" }
|
74
|
-
it_behaves_like 'a call that raises a Youyouaidi::InvalidUUIDError with a meaningful error message'
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe '.parse' do
|
79
|
-
let(:param) { '' }
|
80
|
-
let(:action) { Youyouaidi::UUID.parse param }
|
81
|
-
subject { action }
|
82
|
-
|
83
|
-
context 'with valid uuid string' do
|
84
|
-
let(:param) { '550e8400-e29b-41d4-a716-446655440000' }
|
85
|
-
|
86
|
-
it { should be_a Youyouaidi::UUID }
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'with uuid in short format' do
|
90
|
-
let(:param) { '2AuYQJcZeiIeCymkJ7tzTW' }
|
91
|
-
let(:decoded_uuid) { '550e8400-e29b-41d4-a716-446655440000' }
|
92
|
-
|
93
|
-
it { should be_a Youyouaidi::UUID }
|
94
|
-
its(:to_s) { should eq decoded_uuid }
|
95
|
-
end
|
96
|
-
|
97
|
-
context 'with invalid uuid string' do
|
98
|
-
let(:param) { 'Kekse' }
|
99
|
-
let(:error_message_includes) { "`#{param}'" }
|
100
|
-
it_behaves_like 'a call that raises a Youyouaidi::InvalidUUIDError with a meaningful error message'
|
101
|
-
end
|
102
|
-
|
103
|
-
context 'with non-string input' do
|
104
|
-
let(:param) { 1234 }
|
105
|
-
let(:error_message_includes) { "`#{param}'" }
|
106
|
-
it_behaves_like 'a call that raises a Youyouaidi::InvalidUUIDError with a meaningful error message'
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
shared_examples_for 'equality check for two UUID objects' do
|
111
|
-
let(:first_uuid_string) { 'aaaaaaaa-eeee-4444-aaaa-444444444444' }
|
112
|
-
let(:second_uuid_string) { '00000000-bbbb-2222-8888-000000000000' }
|
113
|
-
let(:first_uuid) { Youyouaidi::UUID.new first_uuid_string }
|
114
|
-
let(:second_uuid) { Youyouaidi::UUID.new second_uuid_string }
|
115
|
-
|
116
|
-
subject { action }
|
117
|
-
|
118
|
-
context 'passing a UUID object' do
|
119
|
-
context 'when comparing same instance' do
|
120
|
-
let(:action) { first_uuid.send described_method, first_uuid }
|
121
|
-
it { should be_truthy }
|
122
|
-
end
|
123
|
-
|
124
|
-
context 'when comparing different instances' do
|
125
|
-
let(:action) { first_uuid.send described_method, second_uuid }
|
126
|
-
context 'with same UUID strings' do
|
127
|
-
let(:second_uuid_string) { first_uuid_string }
|
128
|
-
it { should be_truthy }
|
129
|
-
end
|
130
|
-
|
131
|
-
context 'with different UUID strings' do
|
132
|
-
it { should be_falsey }
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
describe '#== (equal operator)' do
|
139
|
-
let(:uuid_string) { 'aaaaaaaa-eeee-4444-aaaa-444444444444' }
|
140
|
-
let(:uuid) { Youyouaidi::UUID.new uuid_string }
|
141
|
-
|
142
|
-
let(:described_method) { :== }
|
143
|
-
it_behaves_like 'equality check for two UUID objects'
|
144
|
-
|
145
|
-
subject { action }
|
146
|
-
|
147
|
-
context 'passing a non-UUID object' do
|
148
|
-
let(:action) { uuid == test_object }
|
149
|
-
|
150
|
-
context 'when this is the UUID as string' do
|
151
|
-
let(:test_object) { uuid_string }
|
152
|
-
it { should be_falsey }
|
153
|
-
end
|
154
|
-
|
155
|
-
context 'when this is a random other object' do
|
156
|
-
let(:test_object) { '123' }
|
157
|
-
it { should be_falsey }
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
describe '#=== (equal operator)' do
|
163
|
-
let(:uuid_string) { 'aaaaaaaa-eeee-4444-aaaa-444444444444' }
|
164
|
-
let(:uuid) { Youyouaidi::UUID.new uuid_string }
|
165
|
-
|
166
|
-
let(:described_method) { :=== }
|
167
|
-
it_behaves_like 'equality check for two UUID objects'
|
168
|
-
|
169
|
-
subject { action }
|
170
|
-
|
171
|
-
context 'passing a non-UUID object' do
|
172
|
-
# rubocop:disable Style/CaseEquality
|
173
|
-
let(:action) { uuid === test_object }
|
174
|
-
# rubocop:enable Style/CaseEquality
|
175
|
-
|
176
|
-
context 'when this is the same UUID as string' do
|
177
|
-
context 'when string is upcase' do
|
178
|
-
let(:test_object) { uuid_string.upcase }
|
179
|
-
it { should be_truthy }
|
180
|
-
end
|
181
|
-
context 'when string is downcase' do
|
182
|
-
let(:test_object) { uuid_string.downcase }
|
183
|
-
it { should be_truthy }
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
context 'when this is a random other object' do
|
188
|
-
let(:test_object) { '123' }
|
189
|
-
it { should be_falsey }
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
describe '#to_s' do
|
195
|
-
let(:uuid_string) { '550e8400-e29b-41d4-a716-446655440000' }
|
196
|
-
let(:uuid) { Youyouaidi::UUID.new uuid_string }
|
197
|
-
subject { uuid.to_s }
|
198
|
-
|
199
|
-
it { should be_a String }
|
200
|
-
it { should eq uuid_string }
|
201
|
-
end
|
202
|
-
|
203
|
-
describe '#to_i' do
|
204
|
-
let(:uuid_string) { '550e8400-e29b-41d4-a716-446655440000' }
|
205
|
-
let(:uuid) { Youyouaidi::UUID.new uuid_string }
|
206
|
-
subject { uuid.to_i }
|
207
|
-
|
208
|
-
it { should be_a Integer }
|
209
|
-
it { should eq 113_059_749_145_936_325_402_354_257_176_981_405_696 }
|
210
|
-
end
|
211
|
-
|
212
|
-
shared_examples_for 'method for short format' do
|
213
|
-
let(:uuid_string) { '550e8400-e29b-41d4-a716-446655440000' }
|
214
|
-
let(:encoded_uuid) { '2AuYQJcZeiIeCymkJ7tzTW' }
|
215
|
-
let(:uuid) { Youyouaidi::UUID.new uuid_string }
|
216
|
-
|
217
|
-
let(:action) { uuid.send method }
|
218
|
-
subject { action }
|
219
|
-
|
220
|
-
it { should be_a String }
|
221
|
-
it { should eq encoded_uuid }
|
222
|
-
end
|
223
|
-
describe '#to_short_string' do
|
224
|
-
let(:method) { :to_short_string }
|
225
|
-
it_behaves_like 'method for short format'
|
226
|
-
end
|
227
|
-
describe '#to_param' do
|
228
|
-
let(:method) { :to_param }
|
229
|
-
it_behaves_like 'method for short format'
|
230
|
-
end
|
231
|
-
|
232
|
-
describe '.valid?' do
|
233
|
-
let(:param) { '' }
|
234
|
-
subject { Youyouaidi::UUID.valid? param }
|
235
|
-
|
236
|
-
context 'with valid uuid' do
|
237
|
-
valid_uuids = %w[550e8400-e29b-41d4-a716-446655440000
|
238
|
-
27f8bc29-be8e-4dc7-8b30-0295b2a5e902]
|
239
|
-
|
240
|
-
valid_uuids.each do |valid_uuid|
|
241
|
-
it "should return true for `#{valid_uuid}`" do
|
242
|
-
expect(Youyouaidi::UUID.valid?(valid_uuid)).to eq true
|
243
|
-
end
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
context 'with invalid uuid' do
|
248
|
-
uuid_string = '550e8400-e29b-41d4-a716-446655440000'
|
249
|
-
encoded_uuid = '2AuYQJcZeiIeCymkJ7tzTW'
|
250
|
-
invalid_uuids = ['Kekse', "aa#{uuid_string}", "#{uuid_string}bb",
|
251
|
-
encoded_uuid.to_s, '550e8400-e29b-41d4-2716-446655440000']
|
252
|
-
|
253
|
-
invalid_uuids.each do |invalid_uuid|
|
254
|
-
it "should return false for `#{invalid_uuid}`" do
|
255
|
-
expect(Youyouaidi::UUID.valid?(invalid_uuid)).to eq false
|
256
|
-
end
|
257
|
-
end
|
258
|
-
end
|
259
|
-
end
|
260
|
-
end
|
261
|
-
# rubocop:enable Metrics/BlockLength
|
data/youyouaidi-revised.gemspec
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
lib = File.expand_path('lib', __dir__)
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require 'youyouaidi/version'
|
6
|
-
|
7
|
-
Gem::Specification.new do |spec|
|
8
|
-
spec.name = 'youyouaidi-revised'
|
9
|
-
spec.version = Youyouaidi::VERSION
|
10
|
-
spec.authors = ['Nicolas Fricke', 'Loran Kloeze']
|
11
|
-
spec.email = ['mail@nicolasfricke.de', 'loran@freedomnet.nl']
|
12
|
-
spec.summary = 'UUID class'
|
13
|
-
spec.description = 'Youyouaidi offers a UUID class for parsing, validating and encoding UUIDs'
|
14
|
-
spec.homepage = 'https://github.com/LoranKloeze/youyouaidi-revised'
|
15
|
-
spec.license = 'MIT'
|
16
|
-
spec.required_ruby_version = '>= 2.7.4'
|
17
|
-
|
18
|
-
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
19
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
-
spec.require_paths = ['lib']
|
22
|
-
|
23
|
-
spec.add_development_dependency 'bundler', '~> 2.0'
|
24
|
-
spec.add_development_dependency 'rake', '~> 10.5'
|
25
|
-
end
|