uuid_helper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.sublime-*
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in uuid_helper.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Daniel Blanco
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.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # UuidHelper
2
+
3
+ The idea is to provide some helper methods like:
4
+
5
+ ```ruby
6
+ ''.to_uuid
7
+ nil.to_uuid
8
+ ```
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'uuid_helper'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install uuid_helper
23
+
24
+ ## Usage
25
+
26
+ Strings
27
+
28
+ ```console
29
+ "".to_uuid
30
+ => #<UUID:0xXXXXXXX UUID:00000000-0000-0000-0000-000000000000>
31
+
32
+ "\x9ANV\xD2\x990\x11\xE1\xA7h\x00\x13r\x84\xC8\xDF".to_uuid
33
+ => #<UUID:0xXXXXXXX UUID:9a4e56d2-9930-11e1-a768-00137284c8df>
34
+
35
+ "3F3B4A403BF011E181F000137284C8DF".to_uuid
36
+ => #<UUID:0xXXXXXXX UUID:3f3b4a40-3bf0-11e1-81f0-00137284c8df>
37
+
38
+ "3f3b4a40-3bf0-11e1-81f0-00137284c8df".to_uuid
39
+ => #<UUID:0xXXXXXXX UUID:3f3b4a40-3bf0-11e1-81f0-00137284c8df>
40
+ ```
41
+ NilClass
42
+
43
+ ```console
44
+ nil.to_uuid
45
+ => #<UUID:0xXXXXXXX UUID:3f3b4a40-3bf0-11e1-81f0-00137284c8df>
46
+ ```
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,45 @@
1
+ require "uuid_helper/version"
2
+
3
+ module UuidHelper
4
+
5
+ #
6
+ # Open Nil class
7
+ #
8
+ NilClass.class_eval do
9
+ #
10
+ # Converts a Nil to an UUID object. View examples below to know how it works.
11
+ #
12
+ # nil.to_uuid
13
+ # => #<UUID:0xXXXXXXX UUID:00000000-0000-0000-0000-000000000000>
14
+ def to_uuid
15
+ UUIDTools::UUID.parse_hexdigest('')
16
+ end
17
+ end
18
+
19
+ String.class_eval do
20
+ #
21
+ # Converts a String to an UUID object. View examples below to know how it works.
22
+ #
23
+ # "".to_uuid
24
+ # => #<UUID:0xXXXXXXX UUID:00000000-0000-0000-0000-000000000000>
25
+ #
26
+ # "\x9ANV\xD2\x990\x11\xE1\xA7h\x00\x13r\x84\xC8\xDF".to_uuid
27
+ # => #<UUID:0xXXXXXXX UUID:9a4e56d2-9930-11e1-a768-00137284c8df>
28
+ #
29
+ # "3F3B4A403BF011E181F000137284C8DF".to_uuid
30
+ # => #<UUID:0x5133d14 UUID:3f3b4a40-3bf0-11e1-81f0-00137284c8df>
31
+ #
32
+ # "3f3b4a40-3bf0-11e1-81f0-00137284c8df".to_uuid
33
+ # => #<UUID:0x5133d14 UUID:3f3b4a40-3bf0-11e1-81f0-00137284c8df>
34
+ #
35
+ def to_uuid
36
+ if self.bytesize == 16
37
+ UUIDTools::UUID.parse_raw(self)
38
+ elsif self.bytesize == 36
39
+ UUIDTools::UUID.parse(self)
40
+ else
41
+ UUIDTools::UUID.parse_hexdigest(self)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module UuidHelper
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/uuid_helper/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Daniel Blanco"]
6
+ gem.email = ["daniel.blancorojas@gmail.com"]
7
+ gem.description = %q{Helpers to use UUID with uuidtools}
8
+ gem.summary = %q{Extends some core classes to add a to_uuid method}
9
+ gem.homepage = "https://github.com/DanielBlanco/uuid_helper"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "uuid_helper"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = UuidHelper::VERSION
17
+
18
+ gem.add_development_dependency "rspec"
19
+
20
+ gem.add_runtime_dependency "uuidtools"
21
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uuid_helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Blanco
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: uuidtools
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Helpers to use UUID with uuidtools
47
+ email:
48
+ - daniel.blancorojas@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE
56
+ - README.md
57
+ - Rakefile
58
+ - lib/uuid_helper.rb
59
+ - lib/uuid_helper/version.rb
60
+ - uuid_helper.gemspec
61
+ homepage: https://github.com/DanielBlanco/uuid_helper
62
+ licenses: []
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.24
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Extends some core classes to add a to_uuid method
85
+ test_files: []