gn_uuid 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +3 -0
- data/.rubocop.yml +10 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +140 -0
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/gn_uuid.gemspec +35 -0
- data/lib/gn_uuid.rb +32 -0
- data/lib/gn_uuid/uuid.rb +33 -0
- data/lib/gn_uuid/version.rb +8 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b61f9a7696746ef2adcbdf7db09b4491e4bb1e59
|
4
|
+
data.tar.gz: 0d0029fbd7b1d3e6cb241c7bc0af190d4ff20d29
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f26e1d84559a74fd9b9d09ffdaa9144191de38bbc79d4faf355be161ac7c7f4dc5b82abf0e14009e25b9ad501ca49f3d96cd946e103a1aad23957c23b9f091be
|
7
|
+
data.tar.gz: fc7f64d798a58bca1a535e06f90760a93b574574090ac6b3556d70ecfbb5a40ef880a07be8d4161e76b0373df10977de756eeff4a3d94a5d811dd59774ce14f9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Dmitry Mozzherin
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
Global Names UUID
|
2
|
+
=================
|
3
|
+
|
4
|
+
[![Gem Version][gem_badge]][gem_link]
|
5
|
+
[![Continuous Integration Status][ci_badge]][ci_link]
|
6
|
+
[![Coverage Status][cov_badge]][cov_link]
|
7
|
+
[![CodeClimate][code_badge]][code_link]
|
8
|
+
[![Dependency Status][dep_badge]][dep_link]
|
9
|
+
|
10
|
+
Gem `gn_uuid` creates UUID version 5 out of scientific name string. It
|
11
|
+
uses `globalnames.org` domain for DNS namespace. There is a 1:1 relationship
|
12
|
+
between the string and the corresponding UUID, so it allows globally connect
|
13
|
+
data about a name string originated from independent sources without a need
|
14
|
+
to negotiate identifiers. You can find more information about UUID v5 from
|
15
|
+
the original [RFC4122][rfc] document.
|
16
|
+
|
17
|
+
Installation
|
18
|
+
------------
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem 'gn_uuid'
|
24
|
+
```
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
$ bundle
|
29
|
+
|
30
|
+
Or install it yourself as:
|
31
|
+
|
32
|
+
$ gem install gn_uuid
|
33
|
+
|
34
|
+
Usage
|
35
|
+
-----
|
36
|
+
|
37
|
+
#### GnUUID.uuid(string, guid = true)
|
38
|
+
|
39
|
+
Parameter | Type | Description
|
40
|
+
-----------|---------|----------------------------------------------------------
|
41
|
+
str | String | Scientific Name String
|
42
|
+
guid | Boolean | `true` returns a String guid, `false` -- UUID object; *default* `true`
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
require "gn_uuid"
|
46
|
+
|
47
|
+
uuid = GnUUID.uuid("Homo sapiens")
|
48
|
+
# output: 16f235a0-e4a3-529c-9b83-bd15fe722110
|
49
|
+
```
|
50
|
+
If you plan to convert uuid into its other formats use
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
uuid = GnUUID.uuid("Homo sapiens", false)
|
54
|
+
# output: urn:uuid:b33e4b19-2399-56c8-9dd3-eff79f221d2f
|
55
|
+
|
56
|
+
# as a 'stanard guid'
|
57
|
+
uuid.to_s
|
58
|
+
# output: b33e4b19-2399-56c8-9dd3-eff79f221d2f
|
59
|
+
|
60
|
+
# as an decimal integer
|
61
|
+
uuid.to_i
|
62
|
+
# output: 30500639462008600581628158843502600464
|
63
|
+
|
64
|
+
# as an URI
|
65
|
+
uuid.to_uri
|
66
|
+
uuid.inspect (alias_method for to_uri)
|
67
|
+
# output: urn:uuid:b33e4b19-2399-56c8-9dd3-eff79f221d2f
|
68
|
+
|
69
|
+
|
70
|
+
# as a 16-bytes string
|
71
|
+
uuid.bytes
|
72
|
+
# output: "\x16\xF25\xA0\xE4\xA3R\x9C\x9B\x83\xBD\x15\xFEr!\x10"
|
73
|
+
|
74
|
+
# return UUID version
|
75
|
+
uuid.version
|
76
|
+
# output: 5
|
77
|
+
```
|
78
|
+
Please note that the internal GnUUID::UUID does not have to be of the version
|
79
|
+
5, but GnUUID.uuid generates only version 5 UUIDs
|
80
|
+
|
81
|
+
#### GnUUID.parse(uuid)
|
82
|
+
|
83
|
+
Takes a uuid string like "b33e4b19-2399-56c8-9dd3-eff79f221d2f" and returns an
|
84
|
+
instance of GnUUID::UUID class. It can parse any UUID, not only version 5
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
uuid = GnUUID.parse("b33e4b19-2399-56c8-9dd3-eff79f221d2f")
|
88
|
+
uuid.inspect
|
89
|
+
# output: urn:uuid:b33e4b19-2399-56c8-9dd3-eff79f221d2f
|
90
|
+
```
|
91
|
+
Development
|
92
|
+
-----------
|
93
|
+
|
94
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
95
|
+
`rake rspec` to run the tests. You can also run `bin/console` for an
|
96
|
+
interactive prompt that will allow you to experiment.
|
97
|
+
|
98
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
99
|
+
release a new version, update the version number in `version.rb`, and then run
|
100
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
101
|
+
git commits and tags, and push the `.gem` file to
|
102
|
+
[rubygems.org](https://rubygems.org).
|
103
|
+
|
104
|
+
Contributing
|
105
|
+
------------
|
106
|
+
|
107
|
+
Bug reports and pull requests are welcome on GitHub at
|
108
|
+
https://github.com/GlobalNamesArchitecture/gn_uuid.
|
109
|
+
|
110
|
+
Acknowledgement
|
111
|
+
---------------
|
112
|
+
|
113
|
+
This gem heavily borrowed ideas and code from [Urabe Shyouhei's][shyouhei]
|
114
|
+
[ruby-uuid gem][uuidgem]
|
115
|
+
|
116
|
+
Copyright
|
117
|
+
---------
|
118
|
+
|
119
|
+
The gem is available as open source under the terms of the [MIT License][mit].
|
120
|
+
|
121
|
+
Author -- [Dmitry Mozzherin][dimus]
|
122
|
+
|
123
|
+
Copyright (c) 2015 [Marine Biological Laboratory][mbl].
|
124
|
+
|
125
|
+
[gem_badge]: https://badge.fury.io/rb/gn_uuid.svg
|
126
|
+
[gem_link]: http://badge.fury.io/rb/gn_uuid
|
127
|
+
[ci_badge]: https://secure.travis-ci.org/GlobalNamesArchitecture/gn_uuid.svg
|
128
|
+
[ci_link]: http://travis-ci.org/GlobalNamesArchitecture/gn_uuid
|
129
|
+
[cov_badge]: https://coveralls.io/repos/GlobalNamesArchitecture/gn_uuid/badge.svg?branch=master
|
130
|
+
[cov_link]: https://coveralls.io/r/GlobalNamesArchitecture/gn_uuid?branch=master
|
131
|
+
[code_badge]: https://codeclimate.com/github/GlobalNamesArchitecture/gn_uuid/badges/gpa.svg
|
132
|
+
[code_link]: https://codeclimate.com/github/GlobalNamesArchitecture/gn_uuid
|
133
|
+
[dep_badge]: https://gemnasium.com/GlobalNamesArchitecture/gn_uuid.png
|
134
|
+
[dep_link]: https://gemnasium.com/GlobalNamesArchitecture/gn_uuid
|
135
|
+
[rfc]: https://www.ietf.org/rfc/rfc4122.txt
|
136
|
+
[mit]: http://opensource.org/licenses/MIT
|
137
|
+
[shyouhei]: https://github.com/shyouhei
|
138
|
+
[uuidgem]: https://github.com/shyouhei/ruby-uuid
|
139
|
+
[dimus]: https://github.com/dimus
|
140
|
+
[mbl]: http://mbl.edu
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gn_uuid"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/gn_uuid.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "gn_uuid/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "gn_uuid"
|
8
|
+
gem.version = GnUUID::VERSION
|
9
|
+
gem.authors = ["Dmitry Mozzherin"]
|
10
|
+
gem.email = ["dmozzherin@gmail.com"]
|
11
|
+
|
12
|
+
gem.summary = "Creates UUID v5 with DNS:globalnames.org namespace"
|
13
|
+
gem.description = "Creates UUID version 5 out of scientific name " \
|
14
|
+
"string. It uses globalnames.org domain for DNS " \
|
15
|
+
"namespace. There is a 1:1 relationship between the " \
|
16
|
+
"string and the corresponding UUID, so it allows " \
|
17
|
+
"globally connect data about a name string originated " \
|
18
|
+
"from independent sources without a need to negotiate " \
|
19
|
+
"identifiers."
|
20
|
+
gem.homepage = "https://github.com/GlobalNamesArchitecture/gn_uuid"
|
21
|
+
gem.license = "MIT"
|
22
|
+
gem.required_ruby_version = ">= 1.9"
|
23
|
+
|
24
|
+
gem.files = `git ls-files -z`.split("\x0").
|
25
|
+
reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
gem.bindir = "exe"
|
27
|
+
gem.executables = gem.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
gem.require_paths = ["lib"]
|
29
|
+
|
30
|
+
gem.add_development_dependency "bundler", "~> 1.7"
|
31
|
+
gem.add_development_dependency "rake", "~> 10.4"
|
32
|
+
gem.add_development_dependency "rspec", "~> 3.2"
|
33
|
+
gem.add_development_dependency "rubocop", "~> 0.31"
|
34
|
+
gem.add_development_dependency "coveralls", "~> 0.8"
|
35
|
+
end
|
data/lib/gn_uuid.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "digest/sha1"
|
2
|
+
require "gn_uuid/version"
|
3
|
+
require "gn_uuid/uuid"
|
4
|
+
|
5
|
+
# UUID version 5 with DNS|globalnames.org namespace
|
6
|
+
module GnUUID
|
7
|
+
GN_NAMESPACE = "\x90\x18\x11\x96\xFE\xCFP\x82\xA4\xC1A\x1DO1L\xDA"
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def uuid(str, guid = true)
|
11
|
+
sha1 = Digest::SHA1.new
|
12
|
+
sha1.update(GN_NAMESPACE)
|
13
|
+
sha1.update(str)
|
14
|
+
res = GnUUID::UUID.new(stamp_v5(sha1.digest[0..15]))
|
15
|
+
guid ? res.to_s : res
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse(obj)
|
19
|
+
str = obj.to_s.gsub(/\Aurn:uuid:/, "")
|
20
|
+
str.gsub!(/[^0-9A-Fa-f]/, "")
|
21
|
+
GnUUID::UUID.new([str[0..31]].pack("H*"))
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def stamp_v5(str)
|
27
|
+
str[6] = (str[6].ord & 0b1111 | 0b101_0000).chr
|
28
|
+
str[8] = (str[8].ord & 0b11_1111 | 0b1000_0000).chr
|
29
|
+
str
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/gn_uuid/uuid.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module GnUUID
|
2
|
+
# handles UUID byte string and it's conversion to different format
|
3
|
+
# NOTE: this is a general UUID class which is not limited to only v5
|
4
|
+
class UUID
|
5
|
+
attr_reader :bytes
|
6
|
+
|
7
|
+
def initialize(bytes)
|
8
|
+
@bytes = bytes
|
9
|
+
@ary = @bytes.unpack("C*")
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
return @str if @str
|
14
|
+
fmt = "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" \
|
15
|
+
"%02x%02x%02x%02x%02x%02x"
|
16
|
+
@str = fmt % @ary
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_i
|
20
|
+
@num ||= @ary.inject(0) { |a, e| a << 8 | e }
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_uri
|
24
|
+
"urn:uuid:" + to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
alias_method :inspect, :to_uri
|
28
|
+
|
29
|
+
def version
|
30
|
+
@ary[6] >> 4
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gn_uuid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dmitry Mozzherin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.31'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.31'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: coveralls
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.8'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.8'
|
83
|
+
description: Creates UUID version 5 out of scientific name string. It uses globalnames.org
|
84
|
+
domain for DNS namespace. There is a 1:1 relationship between the string and the
|
85
|
+
corresponding UUID, so it allows globally connect data about a name string originated
|
86
|
+
from independent sources without a need to negotiate identifiers.
|
87
|
+
email:
|
88
|
+
- dmozzherin@gmail.com
|
89
|
+
executables: []
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files: []
|
92
|
+
files:
|
93
|
+
- ".gitignore"
|
94
|
+
- ".rspec"
|
95
|
+
- ".rubocop.yml"
|
96
|
+
- ".travis.yml"
|
97
|
+
- CHANGELOG.md
|
98
|
+
- Gemfile
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- bin/console
|
103
|
+
- bin/setup
|
104
|
+
- gn_uuid.gemspec
|
105
|
+
- lib/gn_uuid.rb
|
106
|
+
- lib/gn_uuid/uuid.rb
|
107
|
+
- lib/gn_uuid/version.rb
|
108
|
+
homepage: https://github.com/GlobalNamesArchitecture/gn_uuid
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '1.9'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.2.3
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Creates UUID v5 with DNS:globalnames.org namespace
|
132
|
+
test_files: []
|