uuid4 1.2.1 → 1.3.4

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
- SHA1:
3
- metadata.gz: 40dd0f2af493ca5b0bbe31e4ff0b78b4eef6b173
4
- data.tar.gz: a85b9447fafed6c5983b2eddcc85d8e2da91406a
2
+ SHA256:
3
+ metadata.gz: cd72b459e5ec7d4886de25f62bfe4804d10cc9b89a3353aabaa9fc866b88b5b1
4
+ data.tar.gz: 2e0b69300a1c2b1ce8aab2591565e71a9fa691ee294cdfbfb03733125ab5dce2
5
5
  SHA512:
6
- metadata.gz: 9f9baf2e30e8d2473cab8599b1cb845541a6e5dcc90b55426b366afb7e4c1eec96b97bb5a31c32b686095e401976828c736c12adca9c12fb9989fa125d92dcb8
7
- data.tar.gz: 5e5e2bb9fb811b840cabca2c740e6fd43b714e0af33b1111c06493f2d07150dee87e3f8c8679ced1961d8a13d0f44ea222d4d088c9f1a608c2712f187da790d8
6
+ metadata.gz: 4732a30f2fbca3e9732122cff2fc71484459c1f877534e69dc558251e3e4d667e555e7f5b52b2a40cd69497cd88df8343cdc7016083bb96cbfa4dbb305570693
7
+ data.tar.gz: 26610d164e801f0c15abcbf18a5dc4a18ce331e493ad8a09462306c4ed605fe4f75db578174b2731ff76f7277d99765f2718c1263bcb5a524d8d8044102952af
@@ -1,5 +1,8 @@
1
- sudo: false
1
+ dist: xenial
2
2
  language: ruby
3
3
  rvm:
4
- - 2.3.1
5
- before_install: gem install bundler -v 1.12.5
4
+ - 2.6.3
5
+ - 2.5.5
6
+ - 2.4.6
7
+ - 2.3.8
8
+ - jruby-9.2.7.0
@@ -1,4 +1,45 @@
1
- # Changelog
1
+ # CHANGELOG
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Changelog](http://keepachangelog.com/).
5
+
6
+
7
+ ## Unreleased
8
+ ---
9
+
10
+ ### New
11
+
12
+ ### Changes
13
+
14
+ ### Fixes
15
+
16
+ ### Breaks
17
+
18
+
19
+ ## 1.3.4 - (2020-07-28)
20
+ ---
21
+
22
+ ### Fixes
23
+ * Consider newlines when checking base62 format (#5)
24
+
25
+
26
+ ## 1.3.3
27
+
28
+ * Fix error message on type errors (#4)
29
+
30
+ ## 1.3.2
31
+
32
+ * Fix issue when parsing UUIDs (5e47b00)
33
+
34
+ ## 1.3.1
35
+
36
+ * Fix incompatibility with Rubies <2.2 introduced in #1
37
+
38
+ ## 1.3.0
39
+
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)
2
43
 
3
44
  ## 1.2.1
4
45
 
@@ -18,4 +59,4 @@
18
59
 
19
60
  ## 1.0.0
20
61
 
21
- * Initial release.
62
+ * Initial release.
data/Gemfile CHANGED
@@ -4,3 +4,6 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'activesupport'
7
+ gem 'rake-release', '~> 1.2'
8
+ gem 'rake'
9
+ gem 'rspec', '~> 3.0'
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # UUID4
2
2
 
3
- [![Build Status](https://travis-ci.org/jgraichen/uuid4.svg?branch=master)](https://travis-ci.org/jgraichen/uuid4)
3
+ [![Build Status](https://travis-ci.org/jgraichen/uuid4.svg?branch=master)](https://travis-ci.org/jgraichen/uuid4) [![Dependency Status](https://gemnasium.com/badges/github.com/jgraichen/uuid4.svg)](https://gemnasium.com/github.com/jgraichen/uuid4) [![Gem](https://img.shields.io/gem/v/uuid4.svg)](https://rubygems.org/gems/uuid4) [![license](https://img.shields.io/github/license/jgraichen/uuid4.svg)](https://github.com/jgraichen/uuid4/blob/master/LICENSE.txt)
4
4
 
5
5
  A UUID support library specialized on v4 UUIDs, parsing and formatting existing UUIDs. It can encode and decode dashed UUIDs, compact UUIDs, large integers, UUID URNs and Base62 coded UUIDs.
6
6
 
data/Rakefile CHANGED
@@ -1,6 +1,10 @@
1
- require "bundler/gem_tasks"
1
+ require "rake/release/task"
2
2
  require "rspec/core/rake_task"
3
3
 
4
+ task :default => :spec
5
+
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ Rake::Release::Task.new do |spec|
9
+ spec.sign_tag = true
10
+ end
@@ -60,6 +60,14 @@ class UUID4
60
60
 
61
61
  alias_method :to_i, :to_int
62
62
 
63
+ def hash
64
+ @value.hash
65
+ end
66
+
67
+ def eql?(object)
68
+ object.is_a?(::UUID4) && object.hash === hash
69
+ end
70
+
63
71
  def inspect
64
72
  "<UUID4:#{to_s}>"
65
73
  end
@@ -79,33 +87,46 @@ class UUID4
79
87
  attr_reader :value
80
88
 
81
89
  class << self
90
+ alias _new new
91
+ private :_new
92
+
82
93
  def new(value = nil)
83
94
  if value.nil?
84
95
  super(SecureRandom.uuid.tr('-', '').hex)
85
- elsif value.is_a?(UUID4)
96
+ elsif (uuid = try_convert(value))
97
+ uuid
98
+ else
99
+ raise TypeError.new "Invalid UUID: #{value.inspect}"
100
+ end
101
+ end
102
+
103
+ def try_convert(value)
104
+ if value.nil? || value.is_a?(::UUID4)
86
105
  value
87
106
  elsif value.respond_to?(:to_uuid4)
88
107
  value.to_uuid4
89
- elsif value.respond_to?(:to_int) && valid_int?(value = value.to_int)
90
- super(value)
91
- elsif (ret = _parse(value))
92
- super(ret)
108
+ elsif (value = _parse(value))
109
+ _new value
110
+ end
111
+ end
112
+
113
+ def valid?(value)
114
+ if value.is_a?(::UUID4)
115
+ true
93
116
  else
94
- raise TypeError.new "Invalid UUID: #{value.inspect}"
117
+ !try_convert(value).nil?
95
118
  end
96
119
  end
97
120
 
98
121
  def _parse(value)
99
122
  if value.respond_to?(:to_int) && valid_int?(value = value.to_int)
100
- return value
101
- end
102
-
103
- FORMATTERS.each do |formatter|
104
- val = formatter.decode(value) if formatter.respond_to?(:decode)
105
- return val if val
123
+ value
124
+ else
125
+ # Return the result of the first formatter that can decode this value
126
+ FORMATTERS.lazy.map { |formatter|
127
+ formatter.decode(value) if formatter.respond_to?(:decode)
128
+ }.find {|value| !value.nil? }
106
129
  end
107
-
108
- nil
109
130
  end
110
131
 
111
132
  def valid_int?(int)
@@ -3,7 +3,7 @@ require 'base62-rb'
3
3
  class UUID4
4
4
  module Formatter
5
5
  class Base62
6
- REGEXP = /^[0-9A-z]{14,22}$/i
6
+ REGEXP = /\A[0-9A-Za-z]{14,22}\z/
7
7
 
8
8
  def encode(uuid)
9
9
  ::Base62.encode(uuid.to_i)
@@ -1,8 +1,8 @@
1
1
  class UUID4
2
2
  module VERSION
3
3
  MAJOR = 1
4
- MINOR = 2
5
- PATCH = 1
4
+ MINOR = 3
5
+ PATCH = 4
6
6
  STAGE = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.')
8
8
 
@@ -20,7 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_runtime_dependency 'base62-rb', '~> 0.3.0'
22
22
 
23
- spec.add_development_dependency 'bundler', '~> 1.12'
24
- spec.add_development_dependency 'rake', '~> 10.0'
25
- spec.add_development_dependency 'rspec', '~> 3.0'
23
+ spec.add_development_dependency 'bundler'
26
24
  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.2.1
4
+ version: 1.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-15 00:00:00.000000000 Z
11
+ date: 2020-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base62-rb
@@ -28,44 +28,16 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.12'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.12'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
31
+ - - ">="
46
32
  - !ruby/object:Gem::Version
47
- version: '10.0'
33
+ version: '0'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '10.0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '3.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
38
+ - - ">="
67
39
  - !ruby/object:Gem::Version
68
- version: '3.0'
40
+ version: '0'
69
41
  description:
70
42
  email:
71
43
  - jg@altimos.de
@@ -109,10 +81,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
81
  - !ruby/object:Gem::Version
110
82
  version: '0'
111
83
  requirements: []
112
- rubyforge_project:
113
- rubygems_version: 2.5.1
84
+ rubygems_version: 3.1.2
114
85
  signing_key:
115
86
  specification_version: 4
116
87
  summary: A UUIDv4 support library
117
88
  test_files: []
118
- has_rdoc: