mongomodel 0.2.1 → 0.2.2
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/lib/mongomodel.rb +1 -0
- data/lib/mongomodel/concerns/associations/belongs_to.rb +2 -2
- data/lib/mongomodel/concerns/associations/has_many_by_ids.rb +1 -1
- data/lib/mongomodel/document/persistence.rb +1 -1
- data/lib/mongomodel/support/configuration.rb +17 -4
- data/lib/mongomodel/support/reference.rb +14 -0
- data/lib/mongomodel/version.rb +1 -1
- data/mongomodel.gemspec +3 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/support/helpers/document_finder_stubs.rb +4 -0
- metadata +4 -3
data/lib/mongomodel.rb
CHANGED
@@ -28,6 +28,7 @@ module MongoModel
|
|
28
28
|
autoload :AbstractClass, 'mongomodel/concerns/abstract_class'
|
29
29
|
autoload :ActiveModelCompatibility, 'mongomodel/concerns/activemodel'
|
30
30
|
|
31
|
+
autoload :Reference, 'mongomodel/support/reference'
|
31
32
|
autoload :MongoOptions, 'mongomodel/support/mongo_options'
|
32
33
|
autoload :MongoOrder, 'mongomodel/support/mongo_order'
|
33
34
|
autoload :MongoOperator, 'mongomodel/support/mongo_operator'
|
@@ -10,8 +10,8 @@ module MongoModel
|
|
10
10
|
end
|
11
11
|
|
12
12
|
properties do |association|
|
13
|
-
property association.foreign_key,
|
14
|
-
property association.type_key,
|
13
|
+
property association.foreign_key, Reference, :internal => true
|
14
|
+
property association.type_key, Reference, :internal => true if association.polymorphic?
|
15
15
|
end
|
16
16
|
|
17
17
|
methods do |association|
|
@@ -6,7 +6,7 @@ module MongoModel
|
|
6
6
|
end
|
7
7
|
|
8
8
|
properties do |association|
|
9
|
-
property association.property_name, Collection[
|
9
|
+
property association.property_name, Collection[Reference], :internal => true, :default => []
|
10
10
|
end
|
11
11
|
|
12
12
|
methods do |association|
|
@@ -5,7 +5,7 @@ module MongoModel
|
|
5
5
|
|
6
6
|
included do
|
7
7
|
undef_method :id if method_defined?(:id)
|
8
|
-
property :id,
|
8
|
+
property :id, Reference, :as => '_id', :default => lambda { |doc| doc.generate_id }
|
9
9
|
|
10
10
|
class_inheritable_writer :collection_name
|
11
11
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_support/core_ext/hash/keys'
|
2
|
+
require 'active_support/core_ext/hash/except'
|
2
3
|
|
3
4
|
module MongoModel
|
4
5
|
class Configuration
|
@@ -19,13 +20,25 @@ module MongoModel
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def establish_connection
|
22
|
-
Mongo::Connection.new(host, port)
|
23
|
+
@connection ||= Mongo::Connection.new(host, port, connection_options)
|
24
|
+
@database = @connection.db(database)
|
25
|
+
end
|
26
|
+
|
27
|
+
def use_database(database)
|
28
|
+
@options['database'] = database
|
29
|
+
establish_connection
|
30
|
+
end
|
31
|
+
|
32
|
+
def connection_options
|
33
|
+
@options.except('host', 'port', 'database').symbolize_keys
|
23
34
|
end
|
24
35
|
|
25
36
|
DEFAULTS = {
|
26
|
-
'host'
|
27
|
-
'port'
|
28
|
-
'database'
|
37
|
+
'host' => 'localhost',
|
38
|
+
'port' => 27017,
|
39
|
+
'database' => 'mongomodel-default',
|
40
|
+
'pool_size' => 5,
|
41
|
+
'timeout' => 5
|
29
42
|
}
|
30
43
|
|
31
44
|
def self.defaults
|
data/lib/mongomodel/version.rb
CHANGED
data/mongomodel.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongomodel}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Sam Pohlenz"]
|
12
|
-
s.date = %q{2010-04-
|
12
|
+
s.date = %q{2010-04-26}
|
13
13
|
s.default_executable = %q{console}
|
14
14
|
s.description = %q{MongoModel is a MongoDB ORM for Ruby/Rails similar to ActiveRecord and DataMapper.}
|
15
15
|
s.email = %q{sam@sampohlenz.com}
|
@@ -75,6 +75,7 @@ Gem::Specification.new do |s|
|
|
75
75
|
"lib/mongomodel/support/mongo_operator.rb",
|
76
76
|
"lib/mongomodel/support/mongo_options.rb",
|
77
77
|
"lib/mongomodel/support/mongo_order.rb",
|
78
|
+
"lib/mongomodel/support/reference.rb",
|
78
79
|
"lib/mongomodel/support/scope.rb",
|
79
80
|
"lib/mongomodel/support/scope/dynamic_finders.rb",
|
80
81
|
"lib/mongomodel/support/scope/finder_methods.rb",
|
data/spec/spec_helper.rb
CHANGED
@@ -32,6 +32,10 @@ module DocumentFinderStubs
|
|
32
32
|
yield if block_given?
|
33
33
|
end
|
34
34
|
|
35
|
+
def stub_delete
|
36
|
+
collection.stub!(:remove)
|
37
|
+
end
|
38
|
+
|
35
39
|
def should_delete(conditions={})
|
36
40
|
selector, options = MongoModel::MongoOptions.new(self, :conditions => conditions).to_a
|
37
41
|
collection.should_receive(:remove).once.with(selector)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Sam Pohlenz
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-26 00:00:00 +09:30
|
18
18
|
default_executable: console
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- lib/mongomodel/support/mongo_operator.rb
|
142
142
|
- lib/mongomodel/support/mongo_options.rb
|
143
143
|
- lib/mongomodel/support/mongo_order.rb
|
144
|
+
- lib/mongomodel/support/reference.rb
|
144
145
|
- lib/mongomodel/support/scope.rb
|
145
146
|
- lib/mongomodel/support/scope/dynamic_finders.rb
|
146
147
|
- lib/mongomodel/support/scope/finder_methods.rb
|