uuid4 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/uuid4.rb +35 -14
- data/lib/uuid4/version.rb +2 -2
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba42502b36d87ad581c49a75fecd0986f5e7300d
|
4
|
+
data.tar.gz: c1aa10e23bdeac041883dc68ffc42dfeaf6189b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 894d8c3b4820762cdb81cb6c58ef0ae0a3a22333351d3e16da416a4d64b00b39a92ea74f586b311559d1c2ce46cd9a77a80d42bbf759b082e01b8119dc443dc0
|
7
|
+
data.tar.gz: 45a20cbd99f390ce85d30ee49d2eba22d773a84f49f67f72923a9f67a359ff5c3dde1a32e25af54cedccbe7916c671ee697b44bb88647a7b1607d72f6f04b59f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.3.0
|
4
|
+
|
5
|
+
* Add `UUID#hash` and `UUID#eql?` for using UUIDs e.g. as hash keys
|
6
|
+
* Add `UUID.try_convert` returning a UUID or `nil`.
|
7
|
+
* Add `UUID.valid?` to validate objects as UUIDs (#1)
|
8
|
+
|
3
9
|
## 1.2.1
|
4
10
|
|
5
11
|
* Improve `#as_json` compatibility by swallowing arbitrary arguments passed by encoders.
|
data/lib/uuid4.rb
CHANGED
@@ -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
|
96
|
+
elsif (value = try_convert(value))
|
86
97
|
value
|
87
|
-
elsif value.respond_to?(:to_uuid4)
|
88
|
-
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)
|
93
98
|
else
|
94
99
|
raise TypeError.new "Invalid UUID: #{value.inspect}"
|
95
100
|
end
|
96
101
|
end
|
97
102
|
|
98
|
-
def
|
99
|
-
if value.
|
100
|
-
|
103
|
+
def try_convert(value)
|
104
|
+
if value.nil? || value.is_a?(::UUID4)
|
105
|
+
value
|
106
|
+
elsif value.respond_to?(:to_uuid4)
|
107
|
+
value.to_uuid4
|
108
|
+
elsif (value = _parse(value))
|
109
|
+
_new value
|
101
110
|
end
|
111
|
+
end
|
102
112
|
|
103
|
-
|
104
|
-
|
105
|
-
|
113
|
+
def valid?(value)
|
114
|
+
if value.is_a?(::UUID4)
|
115
|
+
true
|
116
|
+
else
|
117
|
+
!try_convert(value).nil?
|
106
118
|
end
|
119
|
+
end
|
107
120
|
|
108
|
-
|
121
|
+
def _parse(value)
|
122
|
+
if value.respond_to?(:to_int) && valid_int?(value = value.to_int)
|
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(&:itself)
|
129
|
+
end
|
109
130
|
end
|
110
131
|
|
111
132
|
def valid_int?(int)
|
data/lib/uuid4/version.rb
CHANGED
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.
|
4
|
+
version: 1.3.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: 2016-08-
|
11
|
+
date: 2016-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base62-rb
|
@@ -110,9 +110,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
112
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.6.6
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: A UUIDv4 support library
|
117
117
|
test_files: []
|
118
|
-
has_rdoc:
|