uuid_v6 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +63 -0
- data/lib/uuid_v6.rb +7 -0
- data/lib/uuid_v6/sequence.rb +35 -0
- data/lib/uuid_v6/version.rb +5 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/uuid_v6/sequence_spec.rb +31 -0
- data/spec/uuid_v6_spec.rb +7 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b7a00bcae602438dbe00defd9189c0ed00f2f73779b39ba9cf7d9c19c7fa07fe
|
4
|
+
data.tar.gz: af21209fd88b05c72b8e333b3e9942353e8d0de8aabd973a5f59ba0ba337bd39
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ea686e2e238afdff592effe5f9c86cbce30a00897d7f66199462a4abdb78d237e6e09e7e8cc9a1b7889100d461b7f7e959b91c0441fd697f06c8ea6c0d984b08
|
7
|
+
data.tar.gz: 563aba0a62e0ffb13a8b8c014ad7b6aff0b640521a2c836a58ac3d3c9022eefc3dd96fc7ece66cbbd6ead8e28cde18191cdb75456bd4c0fe179f3cd796fcb84d
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# UUIDv6
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/v-kolesnikov/uuid_v6.svg?branch=master)](https://travis-ci.org/v-kolesnikov/uuid_v6)
|
4
|
+
|
5
|
+
UUID version 6 implementation in Ruby. See http://gh.peabody.io/uuidv6/ for details.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'uuid_v6'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install uuid_v6
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'uuid_v6'
|
27
|
+
|
28
|
+
seq = UUIDv6::Sequence.new
|
29
|
+
|
30
|
+
uid = seq.call
|
31
|
+
=> "137ab4b3-3748-6090-80e3-0c859007c113"
|
32
|
+
|
33
|
+
pp 10.times.map { seq.call }
|
34
|
+
["137ab4e2-8469-69d0-80fe-0c859007c113",
|
35
|
+
"137ab4e2-8469-6aa0-80fe-0c859007c113",
|
36
|
+
"137ab4e2-8469-6af0-80fe-0c859007c113",
|
37
|
+
"137ab4e2-8469-6b40-80fe-0c859007c113",
|
38
|
+
"137ab4e2-8469-6b80-80fe-0c859007c113",
|
39
|
+
"137ab4e2-8469-6bc0-80fe-0c859007c113",
|
40
|
+
"137ab4e2-8469-6c00-80fe-0c859007c113",
|
41
|
+
"137ab4e2-8469-6c40-80fe-0c859007c113",
|
42
|
+
"137ab4e2-8469-6c90-80fe-0c859007c113",
|
43
|
+
"137ab4e2-8469-6cd0-80fe-0c859007c113"]
|
44
|
+
=> ...
|
45
|
+
```
|
46
|
+
|
47
|
+
## Development
|
48
|
+
|
49
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
50
|
+
|
51
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/v-kolesnikov/uuid_v6. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
56
|
+
|
57
|
+
## License
|
58
|
+
|
59
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
60
|
+
|
61
|
+
## Code of Conduct
|
62
|
+
|
63
|
+
Everyone interacting in the UUIDv6 project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/v-kolesnikov/uuid_v6/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/uuid_v6.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uuid'
|
4
|
+
|
5
|
+
module UUIDv6
|
6
|
+
# Usage:
|
7
|
+
# seq = UUIDv6::Sequence.new
|
8
|
+
# uid = seq.call
|
9
|
+
# => "137ab4b3-3748-6090-80e3-0c859007c113"
|
10
|
+
class Sequence
|
11
|
+
attr_reader :uuid_v1
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@uuid_v1 = ::UUID.new
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param uuid [String] UUID version 1 (https://tools.ietf.org/html/rfc4122)
|
18
|
+
def call(uuid = uuid_v1.generate)
|
19
|
+
uh = uuid.tr('-', '')
|
20
|
+
tlo1 = uh[0...5]
|
21
|
+
tlo2 = uh[5...8]
|
22
|
+
tmid = uh[8...12]
|
23
|
+
thig = uh[13...16]
|
24
|
+
rest = uh[16...]
|
25
|
+
uh6 = thig + tmid + tlo1 + '6' + tlo2 + rest
|
26
|
+
to_uuid(uh6)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def to_uuid(str)
|
32
|
+
[str[0..7], str[8..11], str[12..15], str[16..19], str[20..]].join('-')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "uuid_v6"
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
# Enable flags like --only-failures and --next-failure
|
8
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
9
|
+
|
10
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
11
|
+
config.disable_monkey_patching!
|
12
|
+
|
13
|
+
config.expect_with :rspec do |c|
|
14
|
+
c.syntax = :expect
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uuid_v6/sequence'
|
4
|
+
|
5
|
+
RSpec.describe UUIDv6::Sequence do
|
6
|
+
subject(:seq) { described_class.new }
|
7
|
+
|
8
|
+
describe '#call' do
|
9
|
+
subject { seq.() }
|
10
|
+
|
11
|
+
specify { expect(subject).to be_a(String) }
|
12
|
+
specify { expect(subject.size).to eq 36 }
|
13
|
+
|
14
|
+
specify 'idempotent behaviour' do
|
15
|
+
uuid_v1 = ::UUID.new.generate
|
16
|
+
uuid1 = seq.(uuid_v1)
|
17
|
+
uuid2 = seq.(uuid_v1)
|
18
|
+
expect(uuid2).to eq uuid1
|
19
|
+
end
|
20
|
+
|
21
|
+
specify 'chronological order' do
|
22
|
+
values = Array.new(100) { seq.() }
|
23
|
+
expect(values.sort).to eq values
|
24
|
+
end
|
25
|
+
|
26
|
+
specify 'unique values' do
|
27
|
+
values = Array.new(100) { seq.() }
|
28
|
+
expect(values.uniq).to eq values
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: uuid_v6
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vasily Kolesnikov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: uuid
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- re.vkolesnikov@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- README.md
|
35
|
+
- lib/uuid_v6.rb
|
36
|
+
- lib/uuid_v6/sequence.rb
|
37
|
+
- lib/uuid_v6/version.rb
|
38
|
+
- spec/spec_helper.rb
|
39
|
+
- spec/uuid_v6/sequence_spec.rb
|
40
|
+
- spec/uuid_v6_spec.rb
|
41
|
+
homepage: https://github.com/v-kolesnikov/uuid_v6
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.7.7
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: UUID "version 6" implementation in Ruby
|
65
|
+
test_files: []
|