uuidgen 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 82cb055949a8a72763fb989a66604dfdc3873f57
4
+ data.tar.gz: 1d47ad8016b703102968a2acbc58862c19bd6cc9
5
+ SHA512:
6
+ metadata.gz: a6d8325c9e784db7402f727655bc481f53ab1d038e203e90547e5aeeadb2db1baa11fcdea0058653645de795cf415f8627b8f54949106deaa3382ef078d91c7c
7
+ data.tar.gz: ced94c46f5fbc8266221a4257d8a8d6530e8b51bf47422a46a33f347d952ec7f562ea3f42125ae3c282215797ed066a6762b275edf22c57bfbd297af936f8756
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in uuidgen.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 mikamix
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ # UUIDGen
2
+
3
+ [![Build Status](https://travis-ci.org/mikamix/uuidgen.png)](https://travis-ci.org/mikamix/uuidgen)
4
+
5
+ Generate UUID(rfc4122) version 3(based on md5) or version 5(based on sha-1).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'uuidgen'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install uuidgen
22
+
23
+ ## Usage
24
+
25
+ `UUID5.new({SEED_STRING})`
26
+
27
+ or
28
+
29
+ `UUID3.new({SEED_STRING})`
30
+
31
+ You can specify name spaces below with second arg.
32
+
33
+ * NameSpaceDNS
34
+ * NameSpaceURL
35
+ * NameSpaceOID
36
+ * NameSpaceX500
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,7 @@
1
+ require 'uuidgen/version'
2
+ require 'uuidgen/uuid'
3
+ require 'uuidgen/name_space'
4
+ require 'uuidgen/name_based_uuid'
5
+ require 'uuidgen/uuid3'
6
+ require 'uuidgen/uuid5'
7
+
@@ -0,0 +1,16 @@
1
+ module UUIDGen
2
+ class NameBasedUUID < UUID
3
+
4
+ def initialize(name, name_space=NameSpaceDNS)
5
+ concated = name_space.to_hexa_string + name
6
+ decimal_hash = uuid_hash(concated).to_i(16)
7
+ @decimal = set_version(set_reserved(decimal_hash))
8
+ end
9
+
10
+ protected
11
+ def uuid_hash(target)
12
+ raise NotImplementedError
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,18 @@
1
+ module UUIDGen
2
+ class NameSpace < UUID
3
+ def initialize(target)
4
+ @decimal = target.gsub('-', '').hex
5
+ end
6
+
7
+ def to_hexa_string
8
+ to_hex.chars.each_slice(2).map do |first, second|
9
+ (first + second).hex.chr
10
+ end.join
11
+ end
12
+ end
13
+
14
+ NameSpaceDNS = NameSpace.new('6ba7b810-9dad-11d1-80b4-00c04fd430c8')
15
+ NameSpaceURL = NameSpace.new('6ba7b811-9dad-11d1-80b4-00c04fd430c8')
16
+ NameSpaceOID = NameSpace.new('6ba7b812-9dad-11d1-80b4-00c04fd430c8')
17
+ NameSpaceX500 = NameSpace.new('6ba7b814-9dad-11d1-80b4-00c04fd430c8')
18
+ end
@@ -0,0 +1,41 @@
1
+ module UUIDGen
2
+ class UUID
3
+ attr_reader :decimal
4
+
5
+ def to_hex
6
+ @decimal.to_s(16).rjust(32, '0')
7
+ end
8
+
9
+ def to_s
10
+ hex_string = to_hex
11
+ '%s-%s-%s-%s-%s' % [
12
+ hex_string[0, 8],
13
+ hex_string[8, 4],
14
+ hex_string[12, 4],
15
+ hex_string[16, 4],
16
+ hex_string[20, 12]
17
+ ]
18
+ end
19
+
20
+ def eql?(other)
21
+ @decimal == other.decimal
22
+ end
23
+
24
+ def hash
25
+ @decimal.hash
26
+ end
27
+
28
+ protected
29
+ def set_version(decimal)
30
+ decimal & ~(0xf000 << 64) | version << 76
31
+ end
32
+
33
+ def set_reserved(decimal)
34
+ decimal & ~(0xc000 << 48) | 0x8000 << 48
35
+ end
36
+
37
+ def version
38
+ raise NotImplementedError
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,14 @@
1
+ require 'digest/sha1'
2
+
3
+ module UUIDGen
4
+ class UUID3 < NameBasedUUID
5
+ def version
6
+ 3
7
+ end
8
+
9
+ def uuid_hash(target)
10
+ Digest::MD5.hexdigest(target)[0, 32]
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,15 @@
1
+ require 'digest/sha1'
2
+
3
+ module UUIDGen
4
+ class UUID5 < NameBasedUUID
5
+
6
+ def version
7
+ 5
8
+ end
9
+
10
+ def uuid_hash(target)
11
+ Digest::SHA1.hexdigest(target)[0, 32]
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,4 @@
1
+ module UUIDGen
2
+ VERSION = "0.0.2"
3
+ end
4
+
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'uuidgen'
3
+
@@ -0,0 +1,56 @@
1
+ require "spec_helper"
2
+
3
+ include UUIDGen
4
+
5
+ describe UUIDGen do
6
+
7
+ it 'has a version number' do
8
+ expect(UUIDGen::VERSION).not_to be nil
9
+ end
10
+ end
11
+
12
+ describe UUID5 do
13
+
14
+ it "can build with DNS name space" do
15
+ testee = UUID5.new('aaa', NameSpaceDNS)
16
+ expect(testee.to_s).to eq '01d2f0ce-8f47-56e4-9a9c-0f368406feb7'
17
+ end
18
+
19
+ it "can build with URL name space" do
20
+ testee = UUID5.new('aaa', NameSpaceURL)
21
+ expect(testee.to_s).to eq '23932b60-2cbd-5366-9c36-8b374f1954a5'
22
+ end
23
+
24
+ it "can build with OID name space" do
25
+ testee = UUID5.new('aaa', NameSpaceOID)
26
+ expect(testee.to_s).to eq '2849bb91-4780-5e13-aee7-45e164e36bd6'
27
+ end
28
+
29
+ it "can build with X500 name space" do
30
+ testee = UUID5.new('aaa', NameSpaceX500)
31
+ expect(testee.to_s).to eq '2fd21a62-3e57-59f0-ab5b-70c8d382d43f'
32
+ end
33
+ end
34
+
35
+ describe UUID3 do
36
+
37
+ it "can build with DNS name space" do
38
+ testee = UUID3.new('aaa', NameSpaceDNS)
39
+ expect(testee.to_s).to eq 'b6602c76-f86e-32a2-ab42-71dd055ad3cc'
40
+ end
41
+
42
+ it "can build with URL name space" do
43
+ testee = UUID3.new('aaa', NameSpaceURL)
44
+ expect(testee.to_s).to eq '97244334-fe16-3c54-9b44-e16241677b1e'
45
+ end
46
+
47
+ it "can build with OID name space" do
48
+ testee = UUID3.new('aaa', NameSpaceOID)
49
+ expect(testee.to_s).to eq '0b6ec827-961f-39ff-aa77-f5de59903acd'
50
+ end
51
+
52
+ it "can build with X500 name space" do
53
+ testee = UUID3.new('aaa', NameSpaceX500)
54
+ expect(testee.to_s).to eq 'a12a4f2e-a9e0-300e-9742-c6018c23b533'
55
+ end
56
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'uuidgen/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "uuidgen"
8
+ spec.version = UUIDGen::VERSION
9
+ spec.authors = ["mikamix"]
10
+ spec.email = "tmp@mikamix.net"
11
+ spec.homepage = "http://blog.mikamix.net"
12
+ spec.description = "Generate UUID(rfc4122) version 3(based on md5) or version 5(based on sha-1)."
13
+ spec.summary = %q{generate UUID version 3 and 5 based on RFC4122}
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 0"
24
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uuidgen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - mikamix
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-17 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.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Generate UUID(rfc4122) version 3(based on md5) or version 5(based on
56
+ sha-1).
57
+ email: tmp@mikamix.net
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/uuidgen.rb
70
+ - lib/uuidgen/name_based_uuid.rb
71
+ - lib/uuidgen/name_space.rb
72
+ - lib/uuidgen/uuid.rb
73
+ - lib/uuidgen/uuid3.rb
74
+ - lib/uuidgen/uuid5.rb
75
+ - lib/uuidgen/version.rb
76
+ - spec/spec_helper.rb
77
+ - spec/uuid_spec.rb
78
+ - uuidgen.gemspec
79
+ homepage: http://blog.mikamix.net
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.2.2
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: generate UUID version 3 and 5 based on RFC4122
103
+ test_files:
104
+ - spec/spec_helper.rb
105
+ - spec/uuid_spec.rb