uuid4 1.3.4 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd72b459e5ec7d4886de25f62bfe4804d10cc9b89a3353aabaa9fc866b88b5b1
4
- data.tar.gz: 2e0b69300a1c2b1ce8aab2591565e71a9fa691ee294cdfbfb03733125ab5dce2
3
+ metadata.gz: 99f0b79a3986a53e256f938361c66ff0428f4566f943d7ebcb3270c59b48e9c2
4
+ data.tar.gz: a9ed439387f5ef681d6c2bc82358ded1c53c961062f3545d1504cb90223411d7
5
5
  SHA512:
6
- metadata.gz: 4732a30f2fbca3e9732122cff2fc71484459c1f877534e69dc558251e3e4d667e555e7f5b52b2a40cd69497cd88df8343cdc7016083bb96cbfa4dbb305570693
7
- data.tar.gz: 26610d164e801f0c15abcbf18a5dc4a18ce331e493ad8a09462306c4ed605fe4f75db578174b2731ff76f7277d99765f2718c1263bcb5a524d8d8044102952af
6
+ metadata.gz: fb757b4a2cc3424d3451799ffd1f8f5221820cf5c32e16191ab9b3f082f9896ac8f3f0e2a3813d48429763eae0dbf6359547a2f77f451b24641747960eadeef3
7
+ data.tar.gz: 520141a2ca687913081ecbc86d822742bda9f71d2a7abbe2e2585fcbbbee98d2db710859b12387e110c26cdd38ed8d025aa646a088d310aa501c966cabf99888
@@ -0,0 +1,13 @@
1
+ ---
2
+ name: maintenance-cache-clear
3
+ on:
4
+ schedule:
5
+ - cron: "0 0 1 * *"
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ cache-clear:
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: easimon/wipe-cache@v2
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: maintenance-workflow-cleanup
3
+ on:
4
+ schedule:
5
+ - cron: "0 0 1 * *"
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ delete-workflow-runs:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: Mattraks/delete-workflow-runs@v2
13
+ with:
14
+ token: ${{ github.token }}
15
+ repository: ${{ github.repository }}
16
+ retain_days: 180
17
+ keep_minimum_runs: 50
@@ -0,0 +1,53 @@
1
+ ---
2
+ name: test
3
+ on: push
4
+ jobs:
5
+ rspec:
6
+ name: "ruby-${{ matrix.ruby }}"
7
+ runs-on: ubuntu-22.04
8
+
9
+ strategy:
10
+ fail-fast: false
11
+ matrix:
12
+ ruby:
13
+ - "3.3"
14
+ - "3.2"
15
+ - "3.1"
16
+ - "3.0"
17
+ - "2.7"
18
+
19
+ env:
20
+ BUNDLE_WITHOUT: development
21
+
22
+ steps:
23
+ - uses: actions/checkout@master
24
+ - uses: ruby/setup-ruby@v1
25
+ with:
26
+ ruby-version: ${{ matrix.ruby }}
27
+ bundler-cache: true
28
+ env:
29
+ BUNDLE_JOBS: 4
30
+ BUNDLE_RETRY: 3
31
+
32
+ - run: |
33
+ bundle exec rspec --color --format documentation
34
+
35
+ rubocop:
36
+ name: rubocop
37
+ runs-on: ubuntu-22.04
38
+
39
+ env:
40
+ BUNDLE_WITHOUT: development
41
+
42
+ steps:
43
+ - uses: actions/checkout@master
44
+ - uses: ruby/setup-ruby@v1
45
+ with:
46
+ ruby-version: "3.3"
47
+ bundler-cache: true
48
+ env:
49
+ BUNDLE_WITHOUT: development
50
+ BUNDLE_JOBS: 4
51
+ BUNDLE_RETRY: 3
52
+
53
+ - run: bundle exec rubocop --parallel --fail-level E
data/.rubocop.yml ADDED
@@ -0,0 +1,16 @@
1
+ # .rubocop.yml
2
+
3
+ inherit_gem:
4
+ rubocop-config: default.yml
5
+
6
+ AllCops:
7
+ TargetRubyVersion: 2.7
8
+ SuggestExtensions: False
9
+ NewCops: enable
10
+
11
+ RSpec/MultipleMemoizedHelpers:
12
+ Enabled: false
13
+ RSpec/NamedSubject:
14
+ Enabled: false
15
+ RSpec/NestedGroups:
16
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -3,8 +3,8 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Changelog](http://keepachangelog.com/).
5
5
 
6
-
7
6
  ## Unreleased
7
+
8
8
  ---
9
9
 
10
10
  ### New
@@ -15,48 +15,52 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Ch
15
15
 
16
16
  ### Breaks
17
17
 
18
+ ## 1.4.0 - (2024-07-11)
19
+
20
+ ### New
21
+
22
+ - Accept UUID v6/7/8 for parsing
18
23
 
19
24
  ## 1.3.4 - (2020-07-28)
20
- ---
21
25
 
22
26
  ### Fixes
23
- * Consider newlines when checking base62 format (#5)
24
27
 
28
+ - Consider newlines when checking base62 format (#5)
25
29
 
26
30
  ## 1.3.3
27
31
 
28
- * Fix error message on type errors (#4)
32
+ - Fix error message on type errors (#4)
29
33
 
30
34
  ## 1.3.2
31
35
 
32
- * Fix issue when parsing UUIDs (5e47b00)
36
+ - Fix issue when parsing UUIDs (5e47b00)
33
37
 
34
38
  ## 1.3.1
35
39
 
36
- * Fix incompatibility with Rubies <2.2 introduced in #1
40
+ - Fix incompatibility with Rubies <2.2 introduced in #1
37
41
 
38
42
  ## 1.3.0
39
43
 
40
- * Add `UUID#hash` and `UUID#eql?` for using UUIDs e.g. as hash keys
41
- * Add `UUID.try_convert` returning a UUID or `nil`
42
- * Add `UUID.valid?` to validate objects as UUIDs (#1)
44
+ - Add `UUID#hash` and `UUID#eql?` for using UUIDs e.g. as hash keys
45
+ - Add `UUID.try_convert` returning a UUID or `nil`
46
+ - Add `UUID.valid?` to validate objects as UUIDs (#1)
43
47
 
44
48
  ## 1.2.1
45
49
 
46
- * Improve `#as_json` compatibility by swallowing arbitrary arguments passed by encoders.
50
+ - Improve `#as_json` compatibility by swallowing arbitrary arguments passed by encoders.
47
51
 
48
52
  ## 1.2.0
49
53
 
50
- * Add JSON encoding support for ActiveSupport
54
+ - Add JSON encoding support for ActiveSupport
51
55
 
52
56
  ## 1.1.1
53
57
 
54
- * Fix support for numerical small UUIDs
58
+ - Fix support for numerical small UUIDs
55
59
 
56
60
  ## 1.1.0
57
61
 
58
- * Export `Kernel#UUID`.
62
+ - Export `Kernel#UUID`.
59
63
 
60
64
  ## 1.0.0
61
65
 
62
- * Initial release.
66
+ - Initial release.
data/Gemfile CHANGED
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in uuid4.gemspec
4
6
  gemspec
5
7
 
6
8
  gem 'activesupport'
7
- gem 'rake-release', '~> 1.2'
8
9
  gem 'rake'
9
- gem 'rspec', '~> 3.0'
10
+ gem 'rake-release', '~> 1.2'
11
+ gem 'rspec', '~> 3.0'
12
+
13
+ gem 'rubocop-config', github: 'jgraichen/rubocop-config', ref: 'v12', require: false
data/Rakefile CHANGED
@@ -1,10 +1,12 @@
1
- require "rake/release/task"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
3
2
 
4
- task :default => :spec
3
+ require 'rake/release/task'
4
+ require 'rspec/core/rake_task'
5
+
6
+ task default: :spec
5
7
 
6
8
  RSpec::Core::RakeTask.new(:spec)
7
9
 
8
10
  Rake::Release::Task.new do |spec|
9
11
  spec.sign_tag = true
10
- end
12
+ end
@@ -1,20 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'base62-rb'
2
4
 
3
5
  class UUID4
4
6
  module Formatter
5
7
  class Base62
6
- REGEXP = /\A[0-9A-Za-z]{14,22}\z/
8
+ REGEXP = /\A[0-9A-Za-z]{14,22}\z/.freeze
7
9
 
8
10
  def encode(uuid)
9
11
  ::Base62.encode(uuid.to_i)
10
12
  end
11
13
 
12
14
  def decode(value)
13
- if value.respond_to?(:to_str) && (value = value.to_str) =~ REGEXP
14
- if ::UUID4.valid_int?(int = ::Base62.decode(value))
15
- int
16
- end
17
- end
15
+ return unless value.respond_to?(:to_str) && (value = value.to_str) =~ REGEXP
16
+ return unless ::UUID4.valid_int?(int = ::Base62.decode(value))
17
+
18
+ int
18
19
  end
19
20
  end
20
21
  end
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UUID4
2
4
  module Formatter
3
5
  class Compact
4
- REGEXP = /^[\da-f]{12}[1-5][\da-f]{3}[89ab][\da-f]{15}$/i
5
- FORMAT = '%032x'.freeze
6
+ REGEXP = /^[\da-f]{12}[1-8][\da-f]{3}[89ab][\da-f]{15}$/i.freeze
7
+ FORMAT = '%032x'
6
8
 
7
9
  def encode(uuid)
8
10
  FORMAT % uuid.to_int
9
11
  end
10
12
 
11
13
  def decode(value)
12
- if value.respond_to?(:to_str) && (value = value.to_str) =~ REGEXP
13
- value.hex
14
- end
14
+ return unless value.respond_to?(:to_str) && (value = value.to_str) =~ REGEXP
15
+
16
+ value.hex
15
17
  end
16
18
  end
17
19
  end
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UUID4
2
4
  module Formatter
3
5
  class Default
4
- REGEXP = /^[\da-f]{8}-[\da-f]{4}-[1-5][\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i
5
- FORMAT = '%08x-%04x-%04x-%04x-%012x'.freeze
6
+ REGEXP = /^[\da-f]{8}-[\da-f]{4}-[1-8][\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i.freeze
7
+ FORMAT = '%08x-%04x-%04x-%04x-%012x'
6
8
 
7
9
  def encode(uuid)
8
10
  FORMAT % uuid.components
9
11
  end
10
12
 
11
13
  def decode(value)
12
- if value.respond_to?(:to_str) && (value = value.to_str) =~ REGEXP
13
- value.tr('-', '').hex
14
- end
14
+ return unless value.respond_to?(:to_str) && (value = value.to_str) =~ REGEXP
15
+
16
+ value.tr('-', '').hex
15
17
  end
16
18
  end
17
19
  end
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UUID4
2
4
  module Formatter
3
5
  class URN
4
- REGEXP = /^urn:uuid:[\da-f]{8}-[\da-f]{4}-?[1-5][\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i
5
- FORMAT = 'urn:uuid:%08x-%04x-%04x-%04x-%012x'.freeze
6
+ REGEXP = /^urn:uuid:[\da-f]{8}-[\da-f]{4}-?[1-8][\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i.freeze
7
+ FORMAT = 'urn:uuid:%08x-%04x-%04x-%04x-%012x'
6
8
 
7
9
  def encode(uuid)
8
10
  FORMAT % uuid.components
9
11
  end
10
12
 
11
13
  def decode(value)
12
- if value.respond_to?(:to_str) && (value = value.to_str) =~ REGEXP
13
- value[9..-1].tr('-', '').hex
14
- end
14
+ return unless value.respond_to?(:to_str) && (value = value.to_str) =~ REGEXP
15
+
16
+ value[9..].tr('-', '').hex
15
17
  end
16
18
  end
17
19
  end
data/lib/uuid4/version.rb CHANGED
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class UUID4
2
4
  module VERSION
3
5
  MAJOR = 1
4
- MINOR = 3
5
- PATCH = 4
6
+ MINOR = 4
7
+ PATCH = 0
6
8
  STAGE = nil
7
- STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.')
9
+ STRING = [MAJOR, MINOR, PATCH, STAGE].compact.join('.')
8
10
 
9
11
  def self.to_s
10
12
  STRING
data/lib/uuid4.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uuid4/version'
2
4
 
3
5
  class UUID4
@@ -12,18 +14,20 @@ class UUID4
12
14
  Formatter::Default.new,
13
15
  Formatter::Compact.new,
14
16
  Formatter::URN.new,
15
- Formatter::Base62.new
16
- ]
17
+ Formatter::Base62.new,
18
+ ].freeze
17
19
 
18
20
  def initialize(value)
19
21
  @value = value
20
22
  end
21
23
 
22
24
  def ==(other)
25
+ # rubocop:disable Style/CaseEquality
23
26
  return value === other.to_i if other.is_a?(UUID4)
24
27
  return other.to_uuid4 == self if other.respond_to?(:to_uuid4)
25
28
 
26
29
  self.class._parse(other) === value
30
+ # rubocop:enable Style/CaseEquality
27
31
  end
28
32
 
29
33
  def to_str(format: :default, formatter: nil)
@@ -37,14 +41,14 @@ class UUID4
37
41
  when :base62
38
42
  formatter = FORMATTERS[3]
39
43
  else
40
- raise RuntimeError.new("Unknown format: #{format}")
44
+ raise "Unknown format: #{format}"
41
45
  end
42
46
 
43
47
  formatter.encode(self)
44
48
  end
45
49
 
46
- alias_method :to_s, :to_str
47
- alias_method :to_uuid, :to_str
50
+ alias to_s to_str
51
+ alias to_uuid to_str
48
52
 
49
53
  def as_json(*)
50
54
  to_str
@@ -58,18 +62,20 @@ class UUID4
58
62
  @value
59
63
  end
60
64
 
61
- alias_method :to_i, :to_int
65
+ alias to_i to_int
62
66
 
63
67
  def hash
64
68
  @value.hash
65
69
  end
66
70
 
67
- def eql?(object)
68
- object.is_a?(::UUID4) && object.hash === hash
71
+ def eql?(other)
72
+ # rubocop:disable Style/CaseEquality
73
+ other.is_a?(::UUID4) && other.hash === hash
74
+ # rubocop:enable Style/CaseEquality
69
75
  end
70
76
 
71
77
  def inspect
72
- "<UUID4:#{to_s}>"
78
+ "<UUID4:#{self}>"
73
79
  end
74
80
 
75
81
  def components
@@ -78,7 +84,7 @@ class UUID4
78
84
  (value >> 80) & 0xFFFF,
79
85
  (value >> 64) & 0xFFFF,
80
86
  (value >> 48) & 0xFFFF,
81
- (value >> 0) & 0xFFFFFFFFFFFF
87
+ (value >> 0) & 0xFFFFFFFFFFFF,
82
88
  ]
83
89
  end
84
90
 
@@ -123,9 +129,9 @@ class UUID4
123
129
  value
124
130
  else
125
131
  # Return the result of the first formatter that can decode this value
126
- FORMATTERS.lazy.map { |formatter|
132
+ FORMATTERS.lazy.map do |formatter|
127
133
  formatter.decode(value) if formatter.respond_to?(:decode)
128
- }.find {|value| !value.nil? }
134
+ end.find {|value| !value.nil? } # rubocop:disable Style/MultilineBlockChain
129
135
  end
130
136
  end
131
137
 
@@ -136,11 +142,11 @@ class UUID4
136
142
  end
137
143
 
138
144
  module Kernel
139
- def UUID4(value)
145
+ def UUID4(value) # rubocop:disable Naming/MethodName
140
146
  UUID4.new(value)
141
147
  end
142
148
 
143
- def UUID(value)
149
+ def UUID(value) # rubocop:disable Naming/MethodName
144
150
  UUID4.new(value)
145
151
  end
146
152
  end
data/renovate.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "extends": [
4
+ "local>jgraichen/renovate-config"
5
+ ]
6
+ }
data/uuid4.gemspec CHANGED
@@ -1,5 +1,6 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'uuid4/version'
5
6
 
@@ -9,16 +10,17 @@ Gem::Specification.new do |spec|
9
10
  spec.authors = ['Jan Graichen']
10
11
  spec.email = ['jg@altimos.de']
11
12
 
12
- spec.summary = %q{A UUIDv4 support library}
13
+ spec.summary = 'A UUIDv4 support library'
13
14
  spec.homepage = 'https://github.com/jgraichen/uuid4'
14
15
  spec.license = 'MIT'
15
16
 
16
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
- spec.bindir = 'exe'
18
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
- spec.require_paths = %w(lib)
17
+ spec.metadata['rubygems_mfa_required'] = 'true'
18
+ spec.required_ruby_version = '>= 2.7.0'
20
19
 
21
- spec.add_runtime_dependency 'base62-rb', '~> 0.3.0'
20
+ spec.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) }
23
+ spec.require_paths = %w[lib]
22
24
 
23
- spec.add_development_dependency 'bundler'
25
+ spec.add_dependency 'base62-rb', '~> 0.3.0'
24
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uuid4
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-28 00:00:00.000000000 Z
11
+ date: 2024-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base62-rb
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.3.0
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  description:
42
28
  email:
43
29
  - jg@altimos.de
@@ -45,9 +31,12 @@ executables: []
45
31
  extensions: []
46
32
  extra_rdoc_files: []
47
33
  files:
34
+ - ".github/workflows/maintenance-cache-wipe.yml"
35
+ - ".github/workflows/maintenance-workflow-cleanup.yml"
36
+ - ".github/workflows/test.yml"
48
37
  - ".gitignore"
49
38
  - ".rspec"
50
- - ".travis.yml"
39
+ - ".rubocop.yml"
51
40
  - CHANGELOG.md
52
41
  - Gemfile
53
42
  - LICENSE.txt
@@ -61,11 +50,13 @@ files:
61
50
  - lib/uuid4/formatter/default.rb
62
51
  - lib/uuid4/formatter/urn.rb
63
52
  - lib/uuid4/version.rb
53
+ - renovate.json
64
54
  - uuid4.gemspec
65
55
  homepage: https://github.com/jgraichen/uuid4
66
56
  licenses:
67
57
  - MIT
68
- metadata: {}
58
+ metadata:
59
+ rubygems_mfa_required: 'true'
69
60
  post_install_message:
70
61
  rdoc_options: []
71
62
  require_paths:
@@ -74,14 +65,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
65
  requirements:
75
66
  - - ">="
76
67
  - !ruby/object:Gem::Version
77
- version: '0'
68
+ version: 2.7.0
78
69
  required_rubygems_version: !ruby/object:Gem::Requirement
79
70
  requirements:
80
71
  - - ">="
81
72
  - !ruby/object:Gem::Version
82
73
  version: '0'
83
74
  requirements: []
84
- rubygems_version: 3.1.2
75
+ rubygems_version: 3.5.11
85
76
  signing_key:
86
77
  specification_version: 4
87
78
  summary: A UUIDv4 support library
data/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- dist: xenial
2
- language: ruby
3
- rvm:
4
- - 2.6.3
5
- - 2.5.5
6
- - 2.4.6
7
- - 2.3.8
8
- - jruby-9.2.7.0