diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 7005d2d..15e0e7c 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -2,19 +2,39 @@ name: Ruby on: [push] -jobs: - build: +permissions: + contents: read +jobs: + tests: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: [ + "1.9.3", + "2.0.0", + 2.1, + 2.3, + 2.4, + 2.5, + 2.6, + 2.7, + "3.0", + 3.1, + 3.2, + jruby-9.1, + jruby-9.2, + jruby-9.3, + jruby-9.4, + truffleruby-head + ] + name: ${{ matrix.ruby }} steps: - - uses: actions/checkout@v1 - - name: Set up Ruby 2.6 - uses: actions/setup-ruby@v1 + - uses: actions/checkout@v3 + - uses: actions/setup-ruby@v1 with: - ruby-version: 2.6.x - - name: Build and test with Rake - run: | - gem install bundler - bundle install --jobs 4 --retry 3 - bundle exec rake + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - run: bundle exec rake diff --git a/.gitignore b/.gitignore index b04a8c8..cbe6612 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ # rspec failure tracking .rspec_status +Gemfile.lock diff --git a/Gemfile b/Gemfile index 189b312..5f10ba8 100644 --- a/Gemfile +++ b/Gemfile @@ -1,12 +1,4 @@ # frozen_string_literal: true source 'https://rubygems.org' - -# Specify your gem's dependencies in uuid_v6.gemspec gemspec - -gem 'rake' - -group :test do - gem 'rspec' -end diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 96acada..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,40 +0,0 @@ -PATH - remote: . - specs: - uuid_v6 (0.1.0) - uuid - -GEM - remote: https://rubygems.org/ - specs: - diff-lcs (1.3) - macaddr (1.7.2) - systemu (~> 2.6.5) - rake (12.3.3) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-core (3.8.2) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.4) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.1) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.2) - systemu (2.6.5) - uuid (2.3.9) - macaddr (~> 1.0) - -PLATFORMS - ruby - -DEPENDENCIES - rake - rspec - uuid_v6! - -BUNDLED WITH - 2.0.2 diff --git a/README.md b/README.md index 67abdb8..78487c1 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,32 @@ +[![Gem Version](https://badge.fury.io/rb/uuid_v6.svg)](https://badge.fury.io/rb/uuid_v6) + # UUIDv6 -[![Build Status](https://travis-ci.org/v-kolesnikov/uuid_v6.svg?branch=master)](https://travis-ci.org/v-kolesnikov/uuid_v6) -[![Gem Version](https://badge.fury.io/rb/uuid_v6.svg)](https://badge.fury.io/rb/uuid_v6) +**UUID v6** pure Ruby implementation. See http://gh.peabody.io/uuidv6/ for details. + +The expected[^1] use case for UUIDv6 is as a drop-in replacement for UUIDv1 which offers improved DB locality. If you don’t have the requirement to keep compatibility with UUIDv1 the suggestion is to use UUIDv7 instead. The only real difference between UUIDv6 and UUIDv1 is the order of the timestamp bits. Starting with the 60-bit timestamp, the first 48 bits of the timestamp come first in the UUID (the specification splits this between time_high, and time_mid likely to keep the same terms as RFC 4122). The next 4 bits contain the version (0110 in this case for v6) and then the final 12 bits of the timestamp can be found. This leads to the following difference: + +**UUIDv1** + +``` +0 1 2 3 +0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| time_low | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| time_mid | time_hi_and_version | +``` + +**UUIDv6** -UUID version 6 implementation in Ruby. See http://gh.peabody.io/uuidv6/ for details. +``` +0 1 2 3 +0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| time_high | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| time_mid | time_low_and_version | +``` ## Installation @@ -62,3 +85,5 @@ The gem is available as open source under the terms of the [MIT License](https:/ ## Code of Conduct 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). + +[^1]: https://blog.devgenius.io/analyzing-new-unique-identifier-formats-uuidv6-uuidv7-and-uuidv8-d6cc5cd7391a diff --git a/lib/uuid_v6.rb b/lib/uuid_v6.rb index a1012f7..4cfb993 100644 --- a/lib/uuid_v6.rb +++ b/lib/uuid_v6.rb @@ -3,5 +3,14 @@ require 'uuid_v6/sequence' require 'uuid_v6/version' +# Usage: +# +# UUIDv6.uuid +# => "13bfc94b-6e81-6070-51da-2683e7d73645" module UUIDv6 + extend self + + def uuid + Sequence.new.() + end end diff --git a/lib/uuid_v6/version.rb b/lib/uuid_v6/version.rb index e433e33..1312d76 100644 --- a/lib/uuid_v6/version.rb +++ b/lib/uuid_v6/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module UUIDv6 - VERSION = "0.1.0" + VERSION = "0.1.1" end diff --git a/uuid_v6.gemspec b/uuid_v6.gemspec index 5ead747..edeef4f 100644 --- a/uuid_v6.gemspec +++ b/uuid_v6.gemspec @@ -16,4 +16,5 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_dependency 'uuid' + spec.add_development_dependency 'rspec' end