sixarm_ruby_zid 5.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +2 -0
- data.tar.gz.sig +0 -0
- data/Rakefile +12 -0
- data/lib/sixarm_ruby_zid.rb +6 -0
- data/lib/sixarm_ruby_zid/zid.rb +65 -0
- data/test/sixarm_ruby_zid_test.rb +11 -0
- data/test/sixarm_ruby_zid_test/zid_test.rb +71 -0
- metadata +187 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a2a9308aa73217e6302ad466d756baca1e80e123aa182452b7d704ce37bdfe07
|
4
|
+
data.tar.gz: 3baed1941ef37f4de37990eea1f0756c72f559603dd8b39f6bb0f7336900b88a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2d7c724f9b5d6ace9e44e2a36d2b6dd0535be31582299bc2ba97a72ef7eda246677b29678be7526905a229c4b3ff4e620c4264e0b7d4ed23d4d1f2248314d6d8
|
7
|
+
data.tar.gz: 68b1547592adef639511528adccb4cebd73fe9f5989565aa0d322c3d382267943aea571013db6a6f2af3f32ef33f51f2be93aed47e5a0e6d5b8b1ef660309ba1
|
checksums.yaml.gz.sig
ADDED
data.tar.gz.sig
ADDED
Binary file
|
data/Rakefile
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
=begin rdoc
|
3
|
+
ZID class.
|
4
|
+
=end
|
5
|
+
|
6
|
+
require "securerandom"
|
7
|
+
require "digest/sha2"
|
8
|
+
|
9
|
+
class ZID
|
10
|
+
|
11
|
+
# Generate a new ZID string.
|
12
|
+
#
|
13
|
+
# Example:
|
14
|
+
#
|
15
|
+
# string = ZID.generate
|
16
|
+
# #=> "4bb88af57d4ddc224fecad688442423d"
|
17
|
+
#
|
18
|
+
# Return: [String] A new ZID string
|
19
|
+
#
|
20
|
+
def self.generate
|
21
|
+
SecureRandom.hex
|
22
|
+
end
|
23
|
+
|
24
|
+
# Is a given ZID string valid?
|
25
|
+
#
|
26
|
+
# Example:
|
27
|
+
#
|
28
|
+
# ZID.valid?("4bb88af57d4ddc224fecad688442423d") #=> true
|
29
|
+
# ZID.valid?("hello") #=> false
|
30
|
+
#
|
31
|
+
# Implemenation note: this method tests the string class,
|
32
|
+
# then size, then regex. The test of the string size comes
|
33
|
+
# before the regex because the test of the size runs faster,
|
34
|
+
# and is an optimization for fast-fail because when the string
|
35
|
+
# is not size 32, then the regex doesn't need to be run.
|
36
|
+
#
|
37
|
+
# Return: [true/false]
|
38
|
+
#
|
39
|
+
def self.valid?(string)
|
40
|
+
!!(string && string.is_a?(String) && string.size == 32 && string =~ /\A[0-9a-f]+\z/)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Parse any object to an ZID string.
|
44
|
+
#
|
45
|
+
# This does these steps:
|
46
|
+
#
|
47
|
+
# * Convert the object to a string by calling `#to_s`.
|
48
|
+
# * Convert the string to lower case by calling `#downcase`.
|
49
|
+
# * Delete any non-hex characters.
|
50
|
+
# * Take the first 32 characters.
|
51
|
+
#
|
52
|
+
# Example:
|
53
|
+
#
|
54
|
+
# string = ZID.parse("***FFAD30A1-BE5E-B511-9ED8-976CAB0281B6***")
|
55
|
+
# #=> "ffad30a1be5eb5119ed8976cab0281b6"
|
56
|
+
#
|
57
|
+
# Return: [ZID] A new ZID
|
58
|
+
#
|
59
|
+
def self.parse(object)
|
60
|
+
zid = object.to_s.downcase.gsub(/[^0-9a-f]/,'')[0...32]
|
61
|
+
raise ArgumentError if !ZID.valid?(zid)
|
62
|
+
zid
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "minitest/autorun"
|
3
|
+
require "coveralls"
|
4
|
+
require "simplecov"
|
5
|
+
Coveralls.wear!
|
6
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
7
|
+
SimpleCov::Formatter::HTMLFormatter,
|
8
|
+
Coveralls::SimpleCov::Formatter
|
9
|
+
]
|
10
|
+
SimpleCov.start
|
11
|
+
require "sixarm_ruby_xid"
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "sixarm_ruby_zid_test"
|
3
|
+
|
4
|
+
describe ZID do
|
5
|
+
|
6
|
+
describe "#new" do
|
7
|
+
|
8
|
+
describe "with initialize defaults" do
|
9
|
+
|
10
|
+
it "is a string with the correct length and characters" do
|
11
|
+
zid = ZID.generate
|
12
|
+
zid.must_match /\A[0-9a-f]{32}\z/
|
13
|
+
end
|
14
|
+
|
15
|
+
it "is always different" do
|
16
|
+
seen = Set.new
|
17
|
+
99999.times.each{
|
18
|
+
zid = ZID.generate
|
19
|
+
seen.include?(zid).must_equal false
|
20
|
+
seen.add(zid)
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#valid" do
|
29
|
+
|
30
|
+
describe "with valid string" do
|
31
|
+
it "is true" do
|
32
|
+
ZID.valid?("c3d010bbfec046f59c7fe843d32dab32").must_be_same_as true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "with invalid string" do
|
37
|
+
it "is false" do
|
38
|
+
ZID.valid?("abc").must_be_same_as false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
describe ".parse" do
|
45
|
+
|
46
|
+
it "converts objects to strings" do
|
47
|
+
obj = Minitest::Mock.new
|
48
|
+
obj.expect(:to_s, "!!C3D010BBFEC046F59C7FE843D32DAB32!!")
|
49
|
+
ZID.parse(obj).must_equal "c3d010bbfec046f59c7fe843d32dab32"
|
50
|
+
obj.verify
|
51
|
+
end
|
52
|
+
|
53
|
+
it "converts to lower case" do
|
54
|
+
ZID.parse("C3D010BBFEC046F59C7FE843D32DAB32").must_equal "c3d010bbfec046f59c7fe843d32dab32"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "deletes non-hex characters" do
|
58
|
+
ZID.parse("!!c3d010bb-fec0-46f59c7f-e843d32dab32!!").must_equal "c3d010bbfec046f59c7fe843d32dab32"
|
59
|
+
end
|
60
|
+
|
61
|
+
it "chops at 32 characters" do
|
62
|
+
ZID.parse("c3d010bbfec046f59c7fe843d32dab32aaaaaaaaa").must_equal "c3d010bbfec046f59c7fe843d32dab32"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "raises if the string is invalid" do
|
66
|
+
proc { ZID.parse("abc") }.must_raise ArgumentError
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sixarm_ruby_zid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 5.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- SixArm
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIFPDCCAyQCCQDx7Y5LWGuPPzANBgkqhkiG9w0BAQsFADBgMQswCQYDVQQGEwJV
|
14
|
+
UzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNU2FuIEZyYW5jaXNjbzEP
|
15
|
+
MA0GA1UECgwGU2l4QXJtMRMwEQYDVQQDDApzaXhhcm0uY29tMB4XDTE4MDExMzIy
|
16
|
+
NDYyM1oXDTIwMTAwOTIyNDYyM1owYDELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNh
|
17
|
+
bGlmb3JuaWExFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xDzANBgNVBAoMBlNpeEFy
|
18
|
+
bTETMBEGA1UEAwwKc2l4YXJtLmNvbTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCC
|
19
|
+
Ag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u2i6QV
|
34
|
+
Yl/663wZgWpqrroSnc3PE3lsuTW7quUvayjtqMTU2qrh7i21oB+/Nn+I6gcxYJZb
|
35
|
+
UlK+tvsqoM94U6sFTjw9mDt62MLQGrJtHShS+ZZiGmWj1sKreuwGJnCVDoBk15xa
|
36
|
+
oqlvfvLAMBCqlfrHhvGUfbIMgzb9uXNmCjzYMsQxuIgF6IMis6Kq02NBAR91HPMe
|
37
|
+
2RoY7CdBHMxW+O0tgS2xoQbOwb+ti1j4MbsWpCqS9Mteck0Z7jZpRRrUDjXU+/7Z
|
38
|
+
RmW9HX0oLIoCBDChCcEKG0Ma4IvHUgjv47f5iYpkXuhifiK4xMG/s+T5Euw3Wg9J
|
39
|
+
tzpk/VnZXj7Ek/earx+N/Z+Wtnl2xENm5IF8SFPeI1HFa9NH47pqtxF1YKpNIEVc
|
40
|
+
2xa2BNHSePe7tys/2hbmZuyMu8X5ERmovsabSXB3a+YwtJh5c2jhA21wF7986s0q
|
41
|
+
-----END CERTIFICATE-----
|
42
|
+
date: 2018-05-11 00:00:00.000000000 Z
|
43
|
+
dependencies:
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: minitest
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 5.7.0
|
51
|
+
- - "<"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '6'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 5.7.0
|
61
|
+
- - "<"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '6'
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: sixarm_ruby_minitest_extensions
|
66
|
+
requirement: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 1.0.8
|
71
|
+
- - "<"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '2'
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 1.0.8
|
81
|
+
- - "<"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '2'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rake
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 10.4.2
|
91
|
+
- - "<"
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '11'
|
94
|
+
type: :development
|
95
|
+
prerelease: false
|
96
|
+
version_requirements: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">"
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 10.4.2
|
101
|
+
- - "<"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '11'
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: simplecov
|
106
|
+
requirement: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.10.0
|
111
|
+
- - "<"
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '2'
|
114
|
+
type: :development
|
115
|
+
prerelease: false
|
116
|
+
version_requirements: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 0.10.0
|
121
|
+
- - "<"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '2'
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
name: coveralls
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 0.8.2
|
131
|
+
- - "<"
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '2'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: 0.8.2
|
141
|
+
- - "<"
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '2'
|
144
|
+
description: ZID generates a new random id, suitable for foreign keys, security authentication,
|
145
|
+
unique tracking, etc.
|
146
|
+
email: sixarm@sixarm.com
|
147
|
+
executables: []
|
148
|
+
extensions: []
|
149
|
+
extra_rdoc_files: []
|
150
|
+
files:
|
151
|
+
- Rakefile
|
152
|
+
- lib/sixarm_ruby_zid.rb
|
153
|
+
- lib/sixarm_ruby_zid/zid.rb
|
154
|
+
- test/sixarm_ruby_zid_test.rb
|
155
|
+
- test/sixarm_ruby_zid_test/zid_test.rb
|
156
|
+
homepage: http://sixarm.com/
|
157
|
+
licenses:
|
158
|
+
- Apache-2.0
|
159
|
+
- Artistic-2.0
|
160
|
+
- BSD-3-Clause
|
161
|
+
- GPL-3.0
|
162
|
+
- MIT
|
163
|
+
- MPL-2.0
|
164
|
+
metadata: {}
|
165
|
+
post_install_message:
|
166
|
+
rdoc_options: []
|
167
|
+
require_paths:
|
168
|
+
- lib
|
169
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '2.2'
|
174
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
requirements: []
|
180
|
+
rubyforge_project:
|
181
|
+
rubygems_version: 2.7.6
|
182
|
+
signing_key:
|
183
|
+
specification_version: 4
|
184
|
+
summary: 'SixArm.com → Ruby → ZID: Xeno Identifier'
|
185
|
+
test_files:
|
186
|
+
- test/sixarm_ruby_zid_test.rb
|
187
|
+
- test/sixarm_ruby_zid_test/zid_test.rb
|
metadata.gz.sig
ADDED
Binary file
|