vidibus-uuid 0.3.6 → 0.3.7
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.
- data/.rspec +2 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +43 -0
- data/README.rdoc +8 -5
- data/Rakefile +8 -17
- data/VERSION +1 -1
- data/lib/vidibus-uuid.rb +2 -2
- data/lib/vidibus/uuid.rb +9 -1
- data/lib/vidibus/uuid/mongoid.rb +3 -2
- data/lib/vidibus/validate_uuid.rb +3 -3
- data/spec/spec_helper.rb +5 -8
- data/spec/vidibus/uuid/mongoid_spec.rb +1 -1
- data/spec/vidibus/uuid_spec.rb +41 -0
- data/spec/vidibus/validate_uuid_spec.rb +4 -4
- data/vidibus-uuid.gemspec +11 -12
- metadata +22 -32
- data/spec/spec.opts +0 -2
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (3.0.0)
|
5
|
+
activesupport (= 3.0.0)
|
6
|
+
builder (~> 2.1.2)
|
7
|
+
i18n (~> 0.4.1)
|
8
|
+
activesupport (3.0.0)
|
9
|
+
bson (1.0.4)
|
10
|
+
builder (2.1.2)
|
11
|
+
diff-lcs (1.1.2)
|
12
|
+
i18n (0.4.1)
|
13
|
+
macaddr (1.0.0)
|
14
|
+
mongo (1.0.7)
|
15
|
+
bson (>= 1.0.4)
|
16
|
+
mongoid (2.0.0.beta.17)
|
17
|
+
activemodel (~> 3.0.0)
|
18
|
+
bson (= 1.0.4)
|
19
|
+
mongo (= 1.0.7)
|
20
|
+
tzinfo (~> 0.3.22)
|
21
|
+
will_paginate (~> 3.0.pre)
|
22
|
+
relevance-rcov (0.9.2.1)
|
23
|
+
rspec (2.0.0.beta.20)
|
24
|
+
rspec-core (= 2.0.0.beta.20)
|
25
|
+
rspec-expectations (= 2.0.0.beta.20)
|
26
|
+
rspec-mocks (= 2.0.0.beta.20)
|
27
|
+
rspec-core (2.0.0.beta.20)
|
28
|
+
rspec-expectations (2.0.0.beta.20)
|
29
|
+
diff-lcs (>= 1.1.2)
|
30
|
+
rspec-mocks (2.0.0.beta.20)
|
31
|
+
tzinfo (0.3.23)
|
32
|
+
uuid (2.3.1)
|
33
|
+
macaddr (~> 1.0)
|
34
|
+
will_paginate (3.0.pre2)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
ruby
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
mongoid (~> 2.0.0.beta.17)
|
41
|
+
relevance-rcov
|
42
|
+
rspec (~> 2.0.0.beta.20)
|
43
|
+
uuid (~> 2.3.1)
|
data/README.rdoc
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
This gem is part of the open source SOA framework Vidibus: http://www.vidibus.org
|
4
4
|
|
5
|
-
It generates compact UUIDs. Basically, this is an abstraction of http://github.com/assaf/uuid
|
5
|
+
It generates and validates compact UUIDs. Basically, this is an abstraction of http://github.com/assaf/uuid
|
6
6
|
|
7
7
|
|
8
8
|
== Installation
|
@@ -18,6 +18,9 @@ Then call bundle install on your console.
|
|
18
18
|
|
19
19
|
Vidibus::Uuid.generate
|
20
20
|
# => "b063263064e0012d47b658b035f038ab"
|
21
|
+
|
22
|
+
Vidibus::Uuid.validate("b063263064e0012d47b658b035f038ab")
|
23
|
+
# => true
|
21
24
|
|
22
25
|
|
23
26
|
=== Usage in Mongoid model
|
@@ -33,15 +36,15 @@ This will extend your model as follows:
|
|
33
36
|
|
34
37
|
class MyModel
|
35
38
|
include Mongoid::Document
|
36
|
-
|
39
|
+
|
37
40
|
field :uuid
|
38
41
|
index :uuid, :unique => true
|
39
|
-
|
42
|
+
|
40
43
|
before_validation :generate_uuid
|
41
44
|
validates :uuid, :uniqueness => true, :uuid => true
|
42
|
-
|
45
|
+
|
43
46
|
private
|
44
|
-
|
47
|
+
|
45
48
|
def generate_uuid
|
46
49
|
return unless new_record?
|
47
50
|
self.uuid ||= Vidibus::Uuid.generate
|
data/Rakefile
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require "rubygems"
|
2
2
|
require "rake"
|
3
|
+
require "rake/rdoctask"
|
4
|
+
require "rspec"
|
5
|
+
require "rspec/core/rake_task"
|
3
6
|
|
4
7
|
begin
|
5
8
|
require "jeweler"
|
@@ -10,31 +13,20 @@ begin
|
|
10
13
|
gem.email = "andre@vidibus.com"
|
11
14
|
gem.homepage = "http://github.com/vidibus/vidibus-uuid"
|
12
15
|
gem.authors = ["Andre Pankratz"]
|
13
|
-
gem.
|
14
|
-
gem.
|
15
|
-
gem.add_dependency "uuid"
|
16
|
+
gem.add_dependency "mongoid", "~> 2.0.0.beta.17"
|
17
|
+
gem.add_dependency "uuid", "~> 2.3.1"
|
16
18
|
end
|
17
19
|
Jeweler::GemcutterTasks.new
|
18
20
|
rescue LoadError
|
19
21
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
22
|
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
spec.libs << "lib" << "spec"
|
25
|
-
spec.spec_files = FileList["spec/**/*_spec.rb"]
|
26
|
-
end
|
27
|
-
|
28
|
-
Spec::Rake::SpecTask.new(:rcov) do |t|
|
29
|
-
t.spec_files = FileList['spec/vidibus/**/*_spec.rb']
|
24
|
+
Rspec::Core::RakeTask.new(:rcov) do |t|
|
25
|
+
t.pattern = "spec/**/*_spec.rb"
|
30
26
|
t.rcov = true
|
31
|
-
t.rcov_opts = [
|
27
|
+
t.rcov_opts = ["--exclude", "^spec,/gems/"]
|
32
28
|
end
|
33
29
|
|
34
|
-
task :spec => :check_dependencies
|
35
|
-
task :default => :spec
|
36
|
-
|
37
|
-
require "rake/rdoctask"
|
38
30
|
Rake::RDocTask.new do |rdoc|
|
39
31
|
version = File.exist?("VERSION") ? File.read("VERSION") : ""
|
40
32
|
rdoc.rdoc_dir = "rdoc"
|
@@ -43,4 +35,3 @@ Rake::RDocTask.new do |rdoc|
|
|
43
35
|
rdoc.rdoc_files.include("lib/**/*.rb")
|
44
36
|
rdoc.options << "--charset=utf-8"
|
45
37
|
end
|
46
|
-
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.7
|
data/lib/vidibus-uuid.rb
CHANGED
@@ -4,8 +4,8 @@ require "vidibus/uuid/mongoid"
|
|
4
4
|
|
5
5
|
if defined?(Rails)
|
6
6
|
module Vidibus::Uuid
|
7
|
-
class Engine < ::Rails::Engine; end
|
7
|
+
class Engine < ::Rails::Engine; end
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
ActiveModel::Validations.send(:include, Vidibus::ValidateUuid)
|
11
|
+
ActiveModel::Validations.send(:include, Vidibus::ValidateUuid)
|
data/lib/vidibus/uuid.rb
CHANGED
@@ -2,8 +2,16 @@ require "uuid"
|
|
2
2
|
|
3
3
|
module Vidibus
|
4
4
|
module Uuid
|
5
|
+
|
6
|
+
# Returns a new compact UUID.
|
5
7
|
def self.generate
|
6
8
|
UUID.new.generate(:compact)
|
7
9
|
end
|
10
|
+
|
11
|
+
# Returns true if given UUID is valid.
|
12
|
+
def self.validate(uuid)
|
13
|
+
uuid = uuid.to_s
|
14
|
+
UUID.validate(uuid) && uuid.length == 32
|
15
|
+
end
|
8
16
|
end
|
9
|
-
end
|
17
|
+
end
|
data/lib/vidibus/uuid/mongoid.rb
CHANGED
@@ -2,6 +2,7 @@ module Vidibus
|
|
2
2
|
module Uuid
|
3
3
|
module Mongoid
|
4
4
|
extend ActiveSupport::Concern
|
5
|
+
|
5
6
|
included do
|
6
7
|
field :uuid
|
7
8
|
index :uuid, :unique => true
|
@@ -9,7 +10,7 @@ module Vidibus
|
|
9
10
|
validates :uuid, :uniqueness => true, :uuid => true
|
10
11
|
end
|
11
12
|
|
12
|
-
# Returns UUID as param for
|
13
|
+
# Returns UUID as param for URLs.
|
13
14
|
def to_param
|
14
15
|
uuid
|
15
16
|
end
|
@@ -22,4 +23,4 @@ module Vidibus
|
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
25
|
-
end
|
26
|
+
end
|
@@ -2,12 +2,12 @@ module Vidibus
|
|
2
2
|
module ValidateUuid
|
3
3
|
class UuidValidator < ActiveModel::EachValidator
|
4
4
|
|
5
|
-
# Ensures that every value is of a valid compact UUID format
|
5
|
+
# Ensures that every value is of a valid compact UUID format.
|
6
6
|
def validate_each(record, attribute, value)
|
7
|
-
unless
|
7
|
+
unless Vidibus::Uuid.validate(value)
|
8
8
|
record.errors.add(attribute, :invalid_uuid)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
13
|
-
end
|
13
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,10 +2,8 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
3
3
|
|
4
4
|
require "rubygems"
|
5
|
-
require "active_support/core_ext"
|
6
|
-
require "spec"
|
7
5
|
require "mongoid"
|
8
|
-
require "
|
6
|
+
require "rspec"
|
9
7
|
require "vidibus-uuid"
|
10
8
|
|
11
9
|
Mongoid.configure do |config|
|
@@ -14,11 +12,10 @@ Mongoid.configure do |config|
|
|
14
12
|
config.master = Mongo::Connection.new.db(name)
|
15
13
|
end
|
16
14
|
|
17
|
-
|
18
|
-
config.
|
19
|
-
|
20
|
-
Mongoid.master.collections.select { |c| c.name != 'system.indexes' }.each(&:drop)
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.after :suite do
|
17
|
+
Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&:drop)
|
21
18
|
end
|
22
19
|
end
|
23
20
|
|
24
|
-
I18n.load_path += Dir[File.join('config', 'locales', '**', '*.{rb,yml}')]
|
21
|
+
I18n.load_path += Dir[File.join('config', 'locales', '**', '*.{rb,yml}')]
|
data/spec/vidibus/uuid_spec.rb
CHANGED
@@ -1,8 +1,49 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe "Vidibus::Uuid" do
|
4
|
+
describe ".generate" do
|
5
|
+
|
6
|
+
end
|
4
7
|
it "should return a compact UUID" do
|
5
8
|
uuid = Vidibus::Uuid.generate
|
6
9
|
uuid.length.should eql(32)
|
7
10
|
end
|
11
|
+
|
12
|
+
describe ".validate" do
|
13
|
+
it "should validate a valid compact UUID" do
|
14
|
+
Vidibus::Uuid.validate("ddeb4500668e012d47bb58b035f038ab").should be_true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should validate a valid compact UUID that is given as symbol" do
|
18
|
+
Vidibus::Uuid.validate(:ddeb4500668e012d47bb58b035f038ab).should be_true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should not validate an UUID that is not compact" do
|
22
|
+
Vidibus::Uuid.validate("87a96db0-9a91-012d-59e4-58b035f038ab").should be_false
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should not validate a string that looks like an UUID, but is too short" do
|
26
|
+
Vidibus::Uuid.validate("dbeb4500668e0f839aefg928930efcca").should be_false
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not validate a random symbol" do
|
30
|
+
Vidibus::Uuid.validate(:something).should be_false
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should not validate a random string with 32 characters" do
|
34
|
+
Vidibus::Uuid.validate("somerandomstringwith32characters").should be_false
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should not validate a string containing non-hex characters" do
|
38
|
+
Vidibus::Uuid.validate("xdeb4500668e012d47bb58b035f038ab").should be_false
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should not validate nil" do
|
42
|
+
Vidibus::Uuid.validate(nil).should be_false
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should not validate an empty string" do
|
46
|
+
Vidibus::Uuid.validate("").should be_false
|
47
|
+
end
|
48
|
+
end
|
8
49
|
end
|
@@ -9,7 +9,7 @@ end
|
|
9
9
|
|
10
10
|
describe "Vidibus::ValidateUuid::UuidValidator" do
|
11
11
|
let(:model) { ModelWithValidations.new }
|
12
|
-
|
12
|
+
|
13
13
|
it "should be available as uuid validator for attribute required_uuid" do
|
14
14
|
ModelWithValidations.validators_on(:required_uuid).first.should be_a_kind_of(Vidibus::ValidateUuid::UuidValidator)
|
15
15
|
end
|
@@ -18,18 +18,18 @@ describe "Vidibus::ValidateUuid::UuidValidator" do
|
|
18
18
|
ModelWithValidations.validators_on(:optional_uuid).first.should be_a_kind_of(Vidibus::ValidateUuid::UuidValidator)
|
19
19
|
end
|
20
20
|
|
21
|
-
it "should validate
|
21
|
+
it "should validate valid UUIDs" do
|
22
22
|
model.required_uuid = "ddeb4500668e012d47bb58b035f038ab"
|
23
23
|
model.should be_valid
|
24
24
|
end
|
25
25
|
|
26
|
-
it "should add an error for
|
26
|
+
it "should add an error for invalid UUIDs" do
|
27
27
|
model.required_uuid = "ddeb4500668e0"
|
28
28
|
model.should be_invalid
|
29
29
|
model.errors[:required_uuid].should have(1).error
|
30
30
|
model.errors[:required_uuid].first.should eql("is not a valid UUID")
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
it "should add an error on required_uuid, if empty" do
|
34
34
|
model.required_uuid = ''
|
35
35
|
model.should be_invalid
|
data/vidibus-uuid.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{vidibus-uuid}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Andre Pankratz"]
|
12
|
-
s.date = %q{2010-08
|
12
|
+
s.date = %q{2010-09-08}
|
13
13
|
s.description = %q{Provides UUID generation for Mongoid models. It includes a validator for UUIDs.}
|
14
14
|
s.email = %q{andre@vidibus.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -19,6 +19,9 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
".gitignore",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
22
25
|
"LICENSE",
|
23
26
|
"README.rdoc",
|
24
27
|
"Rakefile",
|
@@ -28,7 +31,6 @@ Gem::Specification.new do |s|
|
|
28
31
|
"lib/vidibus/uuid.rb",
|
29
32
|
"lib/vidibus/uuid/mongoid.rb",
|
30
33
|
"lib/vidibus/validate_uuid.rb",
|
31
|
-
"spec/spec.opts",
|
32
34
|
"spec/spec_helper.rb",
|
33
35
|
"spec/vidibus/uuid/mongoid_spec.rb",
|
34
36
|
"spec/vidibus/uuid_spec.rb",
|
@@ -52,18 +54,15 @@ Gem::Specification.new do |s|
|
|
52
54
|
s.specification_version = 3
|
53
55
|
|
54
56
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
55
|
-
s.
|
56
|
-
s.
|
57
|
-
s.add_runtime_dependency(%q<uuid>, [">= 0"])
|
57
|
+
s.add_runtime_dependency(%q<mongoid>, ["~> 2.0.0.beta.17"])
|
58
|
+
s.add_runtime_dependency(%q<uuid>, ["~> 2.3.1"])
|
58
59
|
else
|
59
|
-
s.add_dependency(%q<
|
60
|
-
s.add_dependency(%q<
|
61
|
-
s.add_dependency(%q<uuid>, [">= 0"])
|
60
|
+
s.add_dependency(%q<mongoid>, ["~> 2.0.0.beta.17"])
|
61
|
+
s.add_dependency(%q<uuid>, ["~> 2.3.1"])
|
62
62
|
end
|
63
63
|
else
|
64
|
-
s.add_dependency(%q<
|
65
|
-
s.add_dependency(%q<
|
66
|
-
s.add_dependency(%q<uuid>, [">= 0"])
|
64
|
+
s.add_dependency(%q<mongoid>, ["~> 2.0.0.beta.17"])
|
65
|
+
s.add_dependency(%q<uuid>, ["~> 2.3.1"])
|
67
66
|
end
|
68
67
|
end
|
69
68
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vidibus-uuid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 7
|
10
|
+
version: 0.3.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andre Pankratz
|
@@ -15,55 +15,43 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08
|
18
|
+
date: 2010-09-08 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
22
|
-
name: rspec
|
23
|
-
prerelease: false
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
33
|
-
type: :development
|
34
|
-
version_requirements: *id001
|
35
21
|
- !ruby/object:Gem::Dependency
|
36
22
|
name: mongoid
|
37
23
|
prerelease: false
|
38
|
-
requirement: &
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
39
25
|
none: false
|
40
26
|
requirements:
|
41
|
-
- -
|
27
|
+
- - ~>
|
42
28
|
- !ruby/object:Gem::Version
|
43
|
-
hash:
|
29
|
+
hash: 62196417
|
44
30
|
segments:
|
45
31
|
- 2
|
46
32
|
- 0
|
47
33
|
- 0
|
48
34
|
- beta
|
49
|
-
-
|
50
|
-
version: 2.0.0.beta.
|
51
|
-
type: :
|
52
|
-
version_requirements: *
|
35
|
+
- 17
|
36
|
+
version: 2.0.0.beta.17
|
37
|
+
type: :runtime
|
38
|
+
version_requirements: *id001
|
53
39
|
- !ruby/object:Gem::Dependency
|
54
40
|
name: uuid
|
55
41
|
prerelease: false
|
56
|
-
requirement: &
|
42
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
57
43
|
none: false
|
58
44
|
requirements:
|
59
|
-
- -
|
45
|
+
- - ~>
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
hash:
|
47
|
+
hash: 1
|
62
48
|
segments:
|
63
|
-
-
|
64
|
-
|
49
|
+
- 2
|
50
|
+
- 3
|
51
|
+
- 1
|
52
|
+
version: 2.3.1
|
65
53
|
type: :runtime
|
66
|
-
version_requirements: *
|
54
|
+
version_requirements: *id002
|
67
55
|
description: Provides UUID generation for Mongoid models. It includes a validator for UUIDs.
|
68
56
|
email: andre@vidibus.com
|
69
57
|
executables: []
|
@@ -76,6 +64,9 @@ extra_rdoc_files:
|
|
76
64
|
files:
|
77
65
|
- .document
|
78
66
|
- .gitignore
|
67
|
+
- .rspec
|
68
|
+
- Gemfile
|
69
|
+
- Gemfile.lock
|
79
70
|
- LICENSE
|
80
71
|
- README.rdoc
|
81
72
|
- Rakefile
|
@@ -85,7 +76,6 @@ files:
|
|
85
76
|
- lib/vidibus/uuid.rb
|
86
77
|
- lib/vidibus/uuid/mongoid.rb
|
87
78
|
- lib/vidibus/validate_uuid.rb
|
88
|
-
- spec/spec.opts
|
89
79
|
- spec/spec_helper.rb
|
90
80
|
- spec/vidibus/uuid/mongoid_spec.rb
|
91
81
|
- spec/vidibus/uuid_spec.rb
|
data/spec/spec.opts
DELETED