mongo_mapper 0.15.3 → 0.15.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -6
- data/lib/mongo_mapper.rb +17 -18
- data/lib/mongo_mapper/extensions/array.rb +1 -1
- data/lib/mongo_mapper/extensions/binary.rb +1 -1
- data/lib/mongo_mapper/extensions/date.rb +1 -1
- data/lib/mongo_mapper/extensions/float.rb +1 -1
- data/lib/mongo_mapper/extensions/hash.rb +1 -1
- data/lib/mongo_mapper/extensions/nil_class.rb +2 -2
- data/lib/mongo_mapper/extensions/object.rb +1 -1
- data/lib/mongo_mapper/extensions/object_id.rb +1 -1
- data/lib/mongo_mapper/extensions/set.rb +1 -1
- data/lib/mongo_mapper/extensions/string.rb +1 -1
- data/lib/mongo_mapper/plugins/associations/many_association.rb +2 -3
- data/lib/mongo_mapper/plugins/associations/{belongs_to_polymorphic_proxy.rb → proxy/belongs_to_polymorphic_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{belongs_to_proxy.rb → proxy/belongs_to_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/proxy/collection.rb +55 -0
- data/lib/mongo_mapper/plugins/associations/{embedded_collection.rb → proxy/embedded_collection.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{in_array_proxy.rb → proxy/in_array_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{in_foreign_array_proxy.rb → proxy/in_foreign_array_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{many_documents_as_proxy.rb → proxy/many_documents_as_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{many_documents_proxy.rb → proxy/many_documents_proxy.rb} +0 -4
- data/lib/mongo_mapper/plugins/associations/{many_embedded_polymorphic_proxy.rb → proxy/many_embedded_polymorphic_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{many_embedded_proxy.rb → proxy/many_embedded_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{many_polymorphic_proxy.rb → proxy/many_polymorphic_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{one_as_proxy.rb → proxy/one_as_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{one_embedded_polymorphic_proxy.rb → proxy/one_embedded_polymorphic_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{one_embedded_proxy.rb → proxy/one_embedded_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{one_proxy.rb → proxy/one_proxy.rb} +0 -0
- data/lib/mongo_mapper/plugins/associations/{proxy.rb → proxy/proxy.rb} +63 -48
- data/lib/mongo_mapper/plugins/associations/single_association.rb +2 -11
- data/lib/mongo_mapper/plugins/dirty.rb +1 -1
- data/lib/mongo_mapper/plugins/keys/key.rb +9 -6
- data/lib/mongo_mapper/plugins/validations.rb +1 -1
- data/lib/mongo_mapper/version.rb +1 -1
- data/spec/examples.txt +1706 -1704
- data/spec/functional/keys_spec.rb +13 -0
- data/spec/unit/associations/proxy_spec.rb +5 -5
- data/spec/unit/extensions_spec.rb +9 -3
- data/spec/unit/inspect_spec.rb +1 -1
- data/spec/unit/key_spec.rb +7 -1
- metadata +33 -19
- data/lib/mongo_mapper/plugins/associations/collection.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 290286ec91fda33bce766c8cacff110abd4027b200fa5279c2ca8afdf68d3ad3
|
4
|
+
data.tar.gz: b38548fb44300f730c70e0e43abe48a7a9785f884d8b28d3d7447afc78a77ec5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eef0f965e3d2b23cafcbfe6d3c39581ef4556e2b606a1668e3c26a2817bd4a75a94635c5102795171f4deeef6a0b52c74ff3bcac6f81c83a69e69d746f369a0b
|
7
|
+
data.tar.gz: '058f0007e68c8e8d3bbe5ea9236615ba252a44b12c5e91042390a8f920a4127cbe2950e8748f088daab02e8a7b8c6eb0a10b226c378cf4330951b1f8e94db898'
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ A Ruby Object Mapper for Mongo.
|
|
6
6
|
|
7
7
|
[<img src="https://github.com/mongomapper/mongomapper/workflows/Ruby/badge.svg?branch=master" alt="Build Status" />](https://github.com/mongomapper/mongomapper/actions?query=workflow%3ARuby+branch%3Amaster)
|
8
8
|
|
9
|
-
[<img src="https://coveralls.io/repos/mongomapper/mongomapper/badge.svg" alt="Coverage Status" />](https://coveralls.io/r/mongomapper/mongomapper)
|
9
|
+
<!-- [<img src="https://coveralls.io/repos/mongomapper/mongomapper/badge.svg" alt="Coverage Status" />](https://coveralls.io/r/mongomapper/mongomapper) -->
|
10
10
|
|
11
11
|
## Install
|
12
12
|
|
@@ -18,16 +18,27 @@ http://mongomapper.com/documentation/
|
|
18
18
|
|
19
19
|
http://rdoc.info/github/mongomapper/mongomapper
|
20
20
|
|
21
|
+
## Open Commit Policy
|
22
|
+
|
23
|
+
Like Rubinius, we're trying out an "open commit policy".
|
24
|
+
|
25
|
+
If you've committed one (code) patch that has been accepted and would like to
|
26
|
+
work some more on the project, send an email to Scott Taylor
|
27
|
+
<scott@railsnewbie.com> along with your commit sha1.
|
28
|
+
|
21
29
|
## Compatibility
|
22
30
|
|
23
31
|
MongoMapper is tested against:
|
24
32
|
|
25
|
-
* MRI 2.4 -
|
33
|
+
* MRI 2.4 - 3.0.1
|
26
34
|
* JRuby (Versions with 1.9 compatibility)
|
27
35
|
|
28
36
|
Additionally, MongoMapper is tested against:
|
29
37
|
|
30
|
-
* Rails 5.0
|
38
|
+
* Rails 5.0 - 5.2
|
39
|
+
* Rails 6.0 - 6.1
|
40
|
+
|
41
|
+
Note, if you are using Ruby 3.0+, you'll need Rails 6.
|
31
42
|
|
32
43
|
## Contributing & Development
|
33
44
|
|
@@ -37,8 +48,8 @@ Additionally, MongoMapper is tested against:
|
|
37
48
|
|
38
49
|
* Fork the project.
|
39
50
|
* Make your feature addition or bug fix. All specs should pass.
|
40
|
-
* Add specs for your changes. This is important so
|
41
|
-
* Commit, do not mess with Rakefile, version, or history. If you want to have your own version, that is fine but bump version in a commit by itself in another branch so a maintainer ignore it when your pull request is merged.
|
51
|
+
* Add specs for your changes. This is important so that it doesn't break in a future version.
|
52
|
+
* Commit, do not mess with Rakefile, version, or history. If you want to have your own version, that is fine but bump version in a commit by itself in another branch so a maintainer can ignore it when your pull request is merged.
|
42
53
|
* Send a pull request. Bonus points for topic branches.
|
43
54
|
|
44
55
|
## Problems or Questions?
|
@@ -47,7 +58,7 @@ Hit up the Google group: http://groups.google.com/group/mongomapper
|
|
47
58
|
|
48
59
|
## Copyright
|
49
60
|
|
50
|
-
Copyright (c) 2009-
|
61
|
+
Copyright (c) 2009-2021 MongoMapper. See LICENSE for details.
|
51
62
|
|
52
63
|
## Contributors
|
53
64
|
|
data/lib/mongo_mapper.rb
CHANGED
@@ -70,25 +70,27 @@ module MongoMapper
|
|
70
70
|
|
71
71
|
module Associations
|
72
72
|
autoload :Base, 'mongo_mapper/plugins/associations/base'
|
73
|
-
autoload :Collection, 'mongo_mapper/plugins/associations/collection'
|
74
|
-
autoload :EmbeddedCollection, 'mongo_mapper/plugins/associations/embedded_collection'
|
75
73
|
autoload :ManyAssociation, 'mongo_mapper/plugins/associations/many_association'
|
76
74
|
autoload :SingleAssociation, 'mongo_mapper/plugins/associations/single_association'
|
77
75
|
autoload :BelongsToAssociation, 'mongo_mapper/plugins/associations/belongs_to_association'
|
78
76
|
autoload :OneAssociation, 'mongo_mapper/plugins/associations/one_association'
|
79
|
-
|
80
|
-
autoload :
|
81
|
-
autoload :
|
82
|
-
autoload :
|
83
|
-
autoload :
|
84
|
-
autoload :
|
85
|
-
autoload :
|
86
|
-
autoload :
|
87
|
-
autoload :
|
88
|
-
autoload :
|
89
|
-
autoload :
|
90
|
-
autoload :
|
91
|
-
autoload :
|
77
|
+
|
78
|
+
autoload :Proxy, 'mongo_mapper/plugins/associations/proxy/proxy'
|
79
|
+
autoload :Collection, 'mongo_mapper/plugins/associations/proxy/collection'
|
80
|
+
autoload :EmbeddedCollection, 'mongo_mapper/plugins/associations/proxy/embedded_collection'
|
81
|
+
autoload :ManyDocumentsProxy, 'mongo_mapper/plugins/associations/proxy/many_documents_proxy'
|
82
|
+
autoload :BelongsToProxy, 'mongo_mapper/plugins/associations/proxy/belongs_to_proxy'
|
83
|
+
autoload :BelongsToPolymorphicProxy, 'mongo_mapper/plugins/associations/proxy/belongs_to_polymorphic_proxy'
|
84
|
+
autoload :ManyPolymorphicProxy, 'mongo_mapper/plugins/associations/proxy/many_polymorphic_proxy'
|
85
|
+
autoload :ManyEmbeddedProxy, 'mongo_mapper/plugins/associations/proxy/many_embedded_proxy'
|
86
|
+
autoload :ManyEmbeddedPolymorphicProxy, 'mongo_mapper/plugins/associations/proxy/many_embedded_polymorphic_proxy'
|
87
|
+
autoload :ManyDocumentsAsProxy, 'mongo_mapper/plugins/associations/proxy/many_documents_as_proxy'
|
88
|
+
autoload :OneProxy, 'mongo_mapper/plugins/associations/proxy/one_proxy'
|
89
|
+
autoload :OneAsProxy, 'mongo_mapper/plugins/associations/proxy/one_as_proxy'
|
90
|
+
autoload :OneEmbeddedProxy, 'mongo_mapper/plugins/associations/proxy/one_embedded_proxy'
|
91
|
+
autoload :OneEmbeddedPolymorphicProxy, 'mongo_mapper/plugins/associations/proxy/one_embedded_polymorphic_proxy'
|
92
|
+
autoload :InArrayProxy, 'mongo_mapper/plugins/associations/proxy/in_array_proxy'
|
93
|
+
autoload :InForeignArrayProxy, 'mongo_mapper/plugins/associations/proxy/in_foreign_array_proxy'
|
92
94
|
end
|
93
95
|
end
|
94
96
|
|
@@ -99,7 +101,4 @@ Dir[File.join(File.dirname(__FILE__), 'mongo_mapper', 'extensions', '*.rb')].eac
|
|
99
101
|
require extension
|
100
102
|
end
|
101
103
|
|
102
|
-
# FIXME: autoload with proxy is failing, need to investigate
|
103
|
-
require 'mongo_mapper/plugins/associations/proxy'
|
104
|
-
|
105
104
|
ActiveSupport.run_load_hooks(:mongo_mapper, MongoMapper)
|
@@ -30,12 +30,11 @@ module MongoMapper
|
|
30
30
|
def setup(model)
|
31
31
|
model.associations_module.module_eval(<<-end_eval, __FILE__, __LINE__ + 1)
|
32
32
|
def #{name}
|
33
|
-
get_proxy(associations[#{name.inspect}])
|
33
|
+
get_proxy(associations[#{name.inspect}]).read
|
34
34
|
end
|
35
35
|
|
36
36
|
def #{name}=(value)
|
37
|
-
get_proxy(associations[#{name.inspect}]).
|
38
|
-
value
|
37
|
+
get_proxy(associations[#{name.inspect}]).write(value)
|
39
38
|
end
|
40
39
|
end_eval
|
41
40
|
|
File without changes
|
data/lib/mongo_mapper/plugins/associations/{belongs_to_proxy.rb → proxy/belongs_to_proxy.rb}
RENAMED
File without changes
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module MongoMapper
|
3
|
+
module Plugins
|
4
|
+
module Associations
|
5
|
+
class Collection < Proxy
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
def to_a
|
9
|
+
load_target
|
10
|
+
|
11
|
+
target.is_a?(Array) ?
|
12
|
+
target :
|
13
|
+
Array(target)
|
14
|
+
end
|
15
|
+
|
16
|
+
alias_method :to_ary, :to_a
|
17
|
+
|
18
|
+
def each(&block)
|
19
|
+
to_a.each(&block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def [](val)
|
23
|
+
objs = to_a
|
24
|
+
objs ? objs[val] : nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def empty?
|
28
|
+
to_a.empty?
|
29
|
+
end
|
30
|
+
|
31
|
+
def size
|
32
|
+
to_a.size
|
33
|
+
end
|
34
|
+
|
35
|
+
def length
|
36
|
+
to_a.length
|
37
|
+
end
|
38
|
+
|
39
|
+
def reset
|
40
|
+
super
|
41
|
+
target = []
|
42
|
+
end
|
43
|
+
|
44
|
+
def read
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
def write(value)
|
49
|
+
replace(value)
|
50
|
+
read
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/mongo_mapper/plugins/associations/{embedded_collection.rb → proxy/embedded_collection.rb}
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/mongo_mapper/plugins/associations/{many_embedded_proxy.rb → proxy/many_embedded_proxy.rb}
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/mongo_mapper/plugins/associations/{one_embedded_proxy.rb → proxy/one_embedded_proxy.rb}
RENAMED
File without changes
|
File without changes
|
@@ -1,19 +1,25 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
require 'forwardable'
|
3
|
+
|
3
4
|
module MongoMapper
|
4
5
|
module Plugins
|
5
6
|
module Associations
|
6
7
|
class Proxy
|
7
8
|
extend Forwardable
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
class << self
|
11
|
+
def define_proxy_method(method)
|
12
|
+
define_method(method) do |*args, &block|
|
13
|
+
proxy_method(method, *args, &block)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
13
17
|
|
14
18
|
attr_reader :proxy_owner, :association, :target
|
15
19
|
|
16
|
-
|
20
|
+
alias_method :proxy_respond_to?, :respond_to?
|
21
|
+
alias_method :proxy_extend, :extend
|
22
|
+
alias_method :proxy_association, :association
|
17
23
|
|
18
24
|
def_delegators :proxy_association, :klass, :options
|
19
25
|
def_delegator :klass, :collection
|
@@ -24,26 +30,30 @@ module MongoMapper
|
|
24
30
|
reset
|
25
31
|
end
|
26
32
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
33
|
+
[
|
34
|
+
:is_a?,
|
35
|
+
:to_mongo,
|
36
|
+
:==,
|
37
|
+
:!=,
|
38
|
+
:nil?,
|
39
|
+
:blank?,
|
40
|
+
:present?,
|
41
|
+
# Active support in rails 3 beta 4 can override to_json after this is loaded,
|
42
|
+
# at least when run in mongomapper tests. The implementation was changed in master
|
43
|
+
# some time after this, so not sure whether this is still a problem.
|
44
|
+
#
|
45
|
+
# In rails 2, this isn't a problem however it also solves an issue where
|
46
|
+
# to_json isn't forwarded because it supports to_json itself
|
47
|
+
:to_json,
|
48
|
+
# see comments to to_json
|
49
|
+
:as_json,
|
50
|
+
].each do |m|
|
51
|
+
define_proxy_method(m)
|
42
52
|
end
|
43
53
|
|
44
54
|
def inspect
|
45
55
|
load_target
|
46
|
-
target.inspect
|
56
|
+
"#<#{self.class.inspect}:#{object_id} #{@target.inspect}>"
|
47
57
|
end
|
48
58
|
|
49
59
|
def loaded?
|
@@ -54,21 +64,6 @@ module MongoMapper
|
|
54
64
|
@loaded = true
|
55
65
|
end
|
56
66
|
|
57
|
-
def nil?
|
58
|
-
load_target
|
59
|
-
target.nil?
|
60
|
-
end
|
61
|
-
|
62
|
-
def blank?
|
63
|
-
load_target
|
64
|
-
target.blank?
|
65
|
-
end
|
66
|
-
|
67
|
-
def present?
|
68
|
-
load_target
|
69
|
-
target.present?
|
70
|
-
end
|
71
|
-
|
72
67
|
def reload
|
73
68
|
reset
|
74
69
|
load_target
|
@@ -87,16 +82,7 @@ module MongoMapper
|
|
87
82
|
end
|
88
83
|
|
89
84
|
def respond_to?(*args)
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
def send(method, *args, &block)
|
94
|
-
if proxy_respond_to?(method, true)
|
95
|
-
super
|
96
|
-
else
|
97
|
-
load_target
|
98
|
-
target.send(method, *args, &block)
|
99
|
-
end
|
85
|
+
super || (load_target && target.respond_to?(*args))
|
100
86
|
end
|
101
87
|
|
102
88
|
def read
|
@@ -104,6 +90,16 @@ module MongoMapper
|
|
104
90
|
@target
|
105
91
|
end
|
106
92
|
|
93
|
+
def write(value)
|
94
|
+
replace(value)
|
95
|
+
read
|
96
|
+
end
|
97
|
+
|
98
|
+
def proxy_method(method, *args, &block)
|
99
|
+
load_target
|
100
|
+
target.public_send(method, *args, &block)
|
101
|
+
end
|
102
|
+
|
107
103
|
protected
|
108
104
|
|
109
105
|
def load_target
|
@@ -138,9 +134,28 @@ module MongoMapper
|
|
138
134
|
false
|
139
135
|
end
|
140
136
|
|
137
|
+
def define_proxy_method(method)
|
138
|
+
metaclass = class << self; self; end
|
139
|
+
metaclass.class_eval do
|
140
|
+
define_proxy_method(method)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def define_and_call_proxy_method(method, *args, &block)
|
145
|
+
define_proxy_method(method)
|
146
|
+
public_send(method, *args, &block)
|
147
|
+
end
|
148
|
+
|
141
149
|
def method_missing(method, *args, &block)
|
142
|
-
|
143
|
-
|
150
|
+
# load the target just in case it isn't loaded
|
151
|
+
load_target
|
152
|
+
|
153
|
+
# only define the method if the target has the method
|
154
|
+
# NOTE: include private methods!
|
155
|
+
if target.respond_to?(method, true)
|
156
|
+
define_and_call_proxy_method(method, *args, &block)
|
157
|
+
else
|
158
|
+
super
|
144
159
|
end
|
145
160
|
end
|
146
161
|
end
|