mongoid_pk_factory 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +66 -0
- data/VERSION +1 -0
- data/lib/mongoid_pk_factory.rb +17 -0
- data/test/mongoid_pk_factory_test.rb +28 -0
- data/test/teststrap.rb +8 -0
- metadata +108 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 gabrielg
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= mongoid_pk_factory
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 gabrielg. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "mongoid_pk_factory"
|
8
|
+
gem.summary = %Q{Adds Mongo PK factory support to Mongoid}
|
9
|
+
gem.description = %Q{Allows for using a primary key factory other than the default in Mongoid}
|
10
|
+
gem.email = "gabriel.gironda@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/gabrielg/mongoid_pk_factory"
|
12
|
+
gem.authors = ["gabrielg"]
|
13
|
+
gem.add_development_dependency "riot", ">= 0"
|
14
|
+
gem.add_development_dependency "yard", ">= 0"
|
15
|
+
gem.add_dependency "mongoid", "~>1.2"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/*_test.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test'
|
34
|
+
test.pattern = 'test/**/*_test.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :test => :check_dependencies
|
44
|
+
|
45
|
+
begin
|
46
|
+
require 'roodi'
|
47
|
+
require 'roodi_task'
|
48
|
+
RoodiTask.new do |t|
|
49
|
+
t.verbose = false
|
50
|
+
end
|
51
|
+
rescue LoadError
|
52
|
+
task :roodi do
|
53
|
+
abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
task :default => :test
|
58
|
+
|
59
|
+
begin
|
60
|
+
require 'yard'
|
61
|
+
YARD::Rake::YardocTask.new
|
62
|
+
rescue LoadError
|
63
|
+
task :yardoc do
|
64
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
65
|
+
end
|
66
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'mongoid'
|
2
|
+
|
3
|
+
Mongoid::Identity.module_eval do
|
4
|
+
protected
|
5
|
+
class << self
|
6
|
+
# Return the proper id for the document.
|
7
|
+
def generate_id
|
8
|
+
if Mongoid.master.pk_factory
|
9
|
+
id_hash = Mongoid.master.pk_factory.create_pk({})
|
10
|
+
id = id_hash['_id'] || id_hash[:_id]
|
11
|
+
else
|
12
|
+
id = Mongo::ObjectID.new
|
13
|
+
end
|
14
|
+
Mongoid.use_object_ids ? id : id.to_s
|
15
|
+
end
|
16
|
+
end # class << self
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'teststrap'
|
2
|
+
|
3
|
+
context "mongoid_pk_factory" do
|
4
|
+
example_document = Class.new
|
5
|
+
example_document.class_eval do
|
6
|
+
include Mongoid::Document
|
7
|
+
end
|
8
|
+
|
9
|
+
context "with default settings" do
|
10
|
+
|
11
|
+
should "use object ID primary keys" do
|
12
|
+
example_document.new.id
|
13
|
+
end.matches(/^[a-f0-9]{24}$/i)
|
14
|
+
|
15
|
+
end # with default settings
|
16
|
+
|
17
|
+
context "with a pk factory set on the mongo driver" do
|
18
|
+
setup do
|
19
|
+
pk_factory = stub!
|
20
|
+
pk_factory.create_pk(anything) { {:_id => "a_primary_key"} }
|
21
|
+
stub(Mongoid.master).pk_factory { pk_factory }
|
22
|
+
end
|
23
|
+
|
24
|
+
should "use the pk generated by the factory" do
|
25
|
+
example_document.new.id
|
26
|
+
end.equals("a_primary_key")
|
27
|
+
end # with a pk factory set on the mongo driver
|
28
|
+
end # mongoid_pk_factory
|
data/test/teststrap.rb
ADDED
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongoid_pk_factory
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- gabrielg
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-29 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: riot
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: yard
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :development
|
43
|
+
version_requirements: *id002
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: mongoid
|
46
|
+
prerelease: false
|
47
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ~>
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 1
|
53
|
+
- 2
|
54
|
+
version: "1.2"
|
55
|
+
type: :runtime
|
56
|
+
version_requirements: *id003
|
57
|
+
description: Allows for using a primary key factory other than the default in Mongoid
|
58
|
+
email: gabriel.gironda@gmail.com
|
59
|
+
executables: []
|
60
|
+
|
61
|
+
extensions: []
|
62
|
+
|
63
|
+
extra_rdoc_files:
|
64
|
+
- LICENSE
|
65
|
+
- README.rdoc
|
66
|
+
files:
|
67
|
+
- .document
|
68
|
+
- .gitignore
|
69
|
+
- LICENSE
|
70
|
+
- README.rdoc
|
71
|
+
- Rakefile
|
72
|
+
- VERSION
|
73
|
+
- lib/mongoid_pk_factory.rb
|
74
|
+
- test/mongoid_pk_factory_test.rb
|
75
|
+
- test/teststrap.rb
|
76
|
+
has_rdoc: true
|
77
|
+
homepage: http://github.com/gabrielg/mongoid_pk_factory
|
78
|
+
licenses: []
|
79
|
+
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options:
|
82
|
+
- --charset=UTF-8
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
version: "0"
|
99
|
+
requirements: []
|
100
|
+
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.3.6
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Adds Mongo PK factory support to Mongoid
|
106
|
+
test_files:
|
107
|
+
- test/mongoid_pk_factory_test.rb
|
108
|
+
- test/teststrap.rb
|