guid_spanner 0.0.3 → 1.0.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 +5 -5
- data/lib/guid_spanner/guid.rb +21 -4
- data/lib/guid_spanner/version.rb +7 -0
- metadata +32 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a3024c1bb267b3801f9e68943d3633079e42eba7a1e05577b6c5977982a846f9
|
4
|
+
data.tar.gz: 117eacf50adb8fbfca44740b9c5fbc0d57b04a43a5d38dddf3c7927d261c3e4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 481674a09c2c500fd0595a5a4e276b50838f86913e44e9bcfbe9cfd22f3216b60a19ecdc9df96e4936aaa44cb9f9153bb0be4f41b62beac1b9c466caafd656f1
|
7
|
+
data.tar.gz: 46bce9eee27a37eea02d5901cd9eb46cdc44a4f649824734a92ae9838574c571ebd3984a1e123a8fe3e87e4d6d2d772a86edf70317bb5649589d89497912e41a
|
data/lib/guid_spanner/guid.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'uuidtools'
|
2
3
|
|
3
4
|
# Module for guid spannering classes
|
4
5
|
module GuidSpanner
|
@@ -18,15 +19,31 @@ module GuidSpanner
|
|
18
19
|
guid_str.delete('-')
|
19
20
|
end
|
20
21
|
|
22
|
+
# converts 32-char or 36-char guid to binary-16 (e.g. to store in MySQL binary(16) GUID column)
|
23
|
+
#
|
24
|
+
# @param guid_str [String] 32 or 36 character GUID/UUID
|
25
|
+
# @return [Binary] Binary representation of guid_str
|
26
|
+
def self.str_to_bin(guid_str)
|
27
|
+
raise GuidSpanner::Exceptions::InvalidUuidFormatError unless valid_32?(guid_str) || valid_36?(guid_str)
|
28
|
+
guid = guid_str.length == 36 ? guid_str : unpack_to_36(guid_str)
|
29
|
+
UUIDTools::UUID.parse(guid).raw
|
30
|
+
end
|
31
|
+
|
32
|
+
# converts binary-16 guid to 36-char (e.g. to convert guid in MySQL binary(16) GUID column)
|
33
|
+
#
|
34
|
+
# @param guid_bin [Binary] 16 byte GUID/UUID
|
35
|
+
# @return [String] 36 character representation of guid_bin
|
36
|
+
def self.bin_to_str(guid_bin)
|
37
|
+
UUIDTools::UUID.parse_raw(guid_bin).to_s
|
38
|
+
end
|
39
|
+
|
21
40
|
class << self
|
22
41
|
def valid_32?(guid_str)
|
23
|
-
|
24
|
-
res ? true : false
|
42
|
+
guid_str =~ /\A\h{32}\z/
|
25
43
|
end
|
26
44
|
|
27
45
|
def valid_36?(guid_str)
|
28
|
-
|
29
|
-
res ? true : false
|
46
|
+
guid_str =~ /\A\h{8}(-\h{4}){3}-\h{12}\z/
|
30
47
|
end
|
31
48
|
end
|
32
49
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guid_spanner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nigel Surtees
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: uuidtools
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,20 @@ dependencies:
|
|
80
94
|
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
description: A collection of utilities for uuid manipulation
|
84
112
|
email: nigel.surtees@sage.com
|
85
113
|
executables: []
|
@@ -90,6 +118,7 @@ files:
|
|
90
118
|
- lib/guid_spanner/exceptions.rb
|
91
119
|
- lib/guid_spanner/exceptions/invalid_uuid_format_error.rb
|
92
120
|
- lib/guid_spanner/guid.rb
|
121
|
+
- lib/guid_spanner/version.rb
|
93
122
|
homepage: http://rubygems.org/gems/guid_spanner
|
94
123
|
licenses: []
|
95
124
|
metadata: {}
|
@@ -109,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
138
|
version: '0'
|
110
139
|
requirements: []
|
111
140
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.
|
141
|
+
rubygems_version: 2.7.7
|
113
142
|
signing_key:
|
114
143
|
specification_version: 4
|
115
144
|
summary: Guid Spanner!
|