torid 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +4 -0
- data/lib/torid.rb +1 -1
- data/lib/torid/uuid.rb +25 -9
- data/tasks/this.rb +6 -2
- data/test/test_uuid.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f00dde7601ef49bef1988ca71448d7e177adeca8
|
4
|
+
data.tar.gz: 46b76fc71876f3e580d99e480c925bfb5ff1b9aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4869b5ba0b7f952ad70b80d6b6113b12f96294ecaa309224c32b00d85afb13d215748407924c8d7da4f99c1b7da57b138a57fbe867df7b50ea07fc8e119e1315
|
7
|
+
data.tar.gz: 775f96e810c9e85fa4e7a17ecfc1f58926315f458d085ed01a8a8a5e008e25a25fc77419196aa94c70b7fb113e4303bce681447f731d1d6571b83a4a8c898fb7
|
data/HISTORY.md
CHANGED
data/lib/torid.rb
CHANGED
data/lib/torid/uuid.rb
CHANGED
@@ -21,11 +21,28 @@ module Torid
|
|
21
21
|
# uuid.node_id # => Integer
|
22
22
|
class UUID
|
23
23
|
|
24
|
-
#
|
24
|
+
# Regular expression that matches the 36 byte 8-4-4-4-12 format
|
25
|
+
REGEX = %r{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}}i
|
26
|
+
|
27
|
+
# Public: Return if the given string matches the UUID regular expression
|
28
|
+
#
|
29
|
+
# str - The String to compare to REGEX
|
25
30
|
#
|
31
|
+
# Examples:
|
32
|
+
#
|
33
|
+
# Torid::UUID.match( "0004fda3-8c73-5e0f-bae4-e9c86e3684a5" ) # => MatchData
|
34
|
+
#
|
35
|
+
# Returns MatchData or nil if there is no match
|
36
|
+
def self.match( str )
|
37
|
+
REGEX.match( str )
|
38
|
+
end
|
39
|
+
|
40
|
+
# Public: Create a Torid::UUID from an existing String.
|
26
41
|
# The String can either be a 16 byte binary string, or a 36byte hexadecimal
|
27
42
|
# UUID in the 8-4-4-4-12 format.
|
28
43
|
#
|
44
|
+
# str - The String from which to create the UUID.
|
45
|
+
#
|
29
46
|
# Examples
|
30
47
|
#
|
31
48
|
# Torid::UUID.from( "0004fda3-8c73-5e0f-bae4-e9c86e3684a5" ) # => Torid::UUID
|
@@ -34,18 +51,15 @@ module Torid
|
|
34
51
|
# Returns a Torid::UUID
|
35
52
|
# Raises ArgumentError if the String is not convertable to a UUID.
|
36
53
|
def self.from( str )
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
when 16
|
41
|
-
from_bytes( str )
|
42
|
-
else
|
43
|
-
raise ArgumentError, "UUID can only be loaded from a 16 byte binary string or a 36 byte formatted UUID string."
|
44
|
-
end
|
54
|
+
return from_bytes( str ) if str.bytesize == 16
|
55
|
+
return from_string( str ) if UUID.match( str )
|
56
|
+
raise ArgumentError, "UUID can only be loaded from a 16 byte binary string or a 36 byte formatted UUID string."
|
45
57
|
end
|
46
58
|
|
47
59
|
# Internal: Create a new UUID from an existing string in the 8-4-4-4-12 format
|
48
60
|
#
|
61
|
+
# str - The String from which to create the UUID.
|
62
|
+
#
|
49
63
|
# Copied from lexical_uuid
|
50
64
|
#
|
51
65
|
# Returns a Torid::UUID
|
@@ -57,6 +71,8 @@ module Torid
|
|
57
71
|
|
58
72
|
# Internal: Create a new UUID from an existing 16 byte String
|
59
73
|
#
|
74
|
+
# str - The String from which to create the UUID.
|
75
|
+
#
|
60
76
|
# Copied from lexical_uuid
|
61
77
|
#
|
62
78
|
# Returns a Torid::UUID
|
data/tasks/this.rb
CHANGED
@@ -25,7 +25,11 @@ class ThisProject
|
|
25
25
|
#
|
26
26
|
# Yields self
|
27
27
|
def initialize(&block)
|
28
|
-
@exclude_from_manifest =
|
28
|
+
@exclude_from_manifest = Regexp.union(/\.(git|DS_Store)/,
|
29
|
+
/^(doc|coverage|pkg|tmp|Gemfile(\.lock)?)/,
|
30
|
+
/^[^\/]+\.gemspec/,
|
31
|
+
/\.(swp|jar|bundle|so|rvmrc|travis.yml)$/,
|
32
|
+
/~$/)
|
29
33
|
@gemspecs = Hash.new
|
30
34
|
yield self if block_given?
|
31
35
|
end
|
@@ -177,7 +181,7 @@ class ThisProject
|
|
177
181
|
if RUBY_VERSION < "1.9.0"
|
178
182
|
platform_gemspec.add_development_dependency( 'rcov', '~> 1.0.0' )
|
179
183
|
else
|
180
|
-
platform_gemspec.add_development_dependency( 'simplecov', '~> 0.
|
184
|
+
platform_gemspec.add_development_dependency( 'simplecov', '~> 0.9' )
|
181
185
|
end
|
182
186
|
end
|
183
187
|
|
data/test/test_uuid.rb
CHANGED
@@ -12,6 +12,23 @@ module Torid
|
|
12
12
|
@guid = "0004fd7d-f50d-e22e-0000-00000000002a"
|
13
13
|
end
|
14
14
|
|
15
|
+
def test_uuid_regex_matches
|
16
|
+
assert_match( Torid::UUID::REGEX, @guid )
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_uuid_match
|
20
|
+
assert( Torid::UUID::REGEX.match( @guid ) )
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_uuid_no_match
|
24
|
+
assert_equal( nil, Torid::UUID::REGEX.match( "foo" ))
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_uuid_match_case_insensitive
|
28
|
+
match_data = Torid::UUID::REGEX.match( @guid.upcase )
|
29
|
+
assert_instance_of( MatchData, match_data )
|
30
|
+
end
|
31
|
+
|
15
32
|
def test_round_trips_bytes
|
16
33
|
uuid = ::Torid::UUID.from( @bytes)
|
17
34
|
assert_equal( @bytes, uuid.bytes )
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: torid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Hinegardner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fnv
|