mongo_mapper-unstable 2009.12.30 → 2010.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -17
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/mongo_mapper/associations/base.rb +19 -10
- data/lib/mongo_mapper/associations/in_array_proxy.rb +137 -0
- data/lib/mongo_mapper/associations/one_proxy.rb +64 -0
- data/lib/mongo_mapper/associations/proxy.rb +7 -4
- data/lib/mongo_mapper/associations.rb +11 -3
- data/lib/mongo_mapper/callbacks.rb +30 -78
- data/lib/mongo_mapper/dirty.rb +5 -24
- data/lib/mongo_mapper/document.rb +117 -144
- data/lib/mongo_mapper/embedded_document.rb +7 -11
- data/lib/mongo_mapper/finder_options.rb +13 -21
- data/lib/mongo_mapper/mongo_mapper.rb +125 -0
- data/lib/mongo_mapper/pagination.rb +12 -1
- data/lib/mongo_mapper/rails_compatibility/embedded_document.rb +1 -0
- data/lib/mongo_mapper/serialization.rb +2 -2
- data/lib/mongo_mapper/serializers/json_serializer.rb +2 -46
- data/lib/mongo_mapper/support.rb +2 -2
- data/lib/mongo_mapper.rb +8 -2
- data/mongo_mapper.gemspec +14 -8
- data/specs.watchr +3 -5
- data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +8 -0
- data/test/functional/associations/test_belongs_to_proxy.rb +54 -9
- data/test/functional/associations/test_in_array_proxy.rb +309 -0
- data/test/functional/associations/test_many_documents_proxy.rb +103 -53
- data/test/functional/associations/test_many_embedded_proxy.rb +4 -14
- data/test/functional/associations/test_many_polymorphic_proxy.rb +2 -1
- data/test/functional/associations/test_one_proxy.rb +149 -0
- data/test/functional/test_binary.rb +13 -4
- data/test/functional/test_callbacks.rb +1 -5
- data/test/functional/test_dirty.rb +1 -4
- data/test/functional/test_document.rb +576 -640
- data/test/functional/test_embedded_document.rb +7 -20
- data/test/functional/test_modifiers.rb +238 -0
- data/test/functional/test_pagination.rb +1 -3
- data/test/functional/test_string_id_compatibility.rb +3 -8
- data/test/functional/test_validations.rb +13 -75
- data/test/models.rb +1 -1
- data/test/support/timing.rb +1 -1
- data/test/test_helper.rb +28 -0
- data/test/unit/associations/test_base.rb +54 -13
- data/test/unit/associations/test_proxy.rb +12 -0
- data/test/unit/test_document.rb +36 -26
- data/test/unit/test_embedded_document.rb +14 -51
- data/test/unit/test_finder_options.rb +20 -7
- data/test/unit/test_key.rb +1 -4
- data/test/unit/test_pagination.rb +6 -0
- data/test/unit/test_rails_compatibility.rb +4 -1
- data/test/unit/test_serializations.rb +1 -2
- data/test/unit/test_support.rb +4 -0
- data/test/unit/test_time_zones.rb +1 -2
- data/test/unit/test_validations.rb +3 -14
- metadata +12 -6
- data/lib/mongo_mapper/observing.rb +0 -50
- data/test/unit/test_observing.rb +0 -101
@@ -53,6 +53,7 @@ class ProxyTest < Test::Unit::TestCase
|
|
53
53
|
context "blank?" do
|
54
54
|
should "be true if blank" do
|
55
55
|
@blank_proxy.blank?.should be_true
|
56
|
+
@nil_proxy.blank?.should be_true
|
56
57
|
end
|
57
58
|
|
58
59
|
should "be false if not blank" do
|
@@ -60,6 +61,17 @@ class ProxyTest < Test::Unit::TestCase
|
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
64
|
+
context "present?" do
|
65
|
+
should "be true if present" do
|
66
|
+
@proxy.present?.should be_true
|
67
|
+
end
|
68
|
+
|
69
|
+
should "be false if not present" do
|
70
|
+
@blank_proxy.present?.should be_false
|
71
|
+
@nil_proxy.present?.should be_false
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
63
75
|
should "delegate respond_to? to target" do
|
64
76
|
@proxy.respond_to?(:each).should be_true
|
65
77
|
@proxy.respond_to?(:size).should be_true
|
data/test/unit/test_document.rb
CHANGED
@@ -4,11 +4,7 @@ require 'models'
|
|
4
4
|
class DocumentTest < Test::Unit::TestCase
|
5
5
|
context "The Document Class" do
|
6
6
|
setup do
|
7
|
-
@document =
|
8
|
-
include MongoMapper::Document
|
9
|
-
set_collection_name 'test'
|
10
|
-
end
|
11
|
-
@document.collection.remove
|
7
|
+
@document = Doc()
|
12
8
|
end
|
13
9
|
|
14
10
|
should "have logger method" do
|
@@ -40,10 +36,7 @@ class DocumentTest < Test::Unit::TestCase
|
|
40
36
|
@document.database_name.should == 'test2'
|
41
37
|
@document.database.name.should == 'test2'
|
42
38
|
|
43
|
-
another_document =
|
44
|
-
include MongoMapper::Document
|
45
|
-
set_collection_name 'test'
|
46
|
-
end
|
39
|
+
another_document = Doc()
|
47
40
|
another_document.database.should == MongoMapper.database
|
48
41
|
end
|
49
42
|
|
@@ -72,6 +65,34 @@ class DocumentTest < Test::Unit::TestCase
|
|
72
65
|
@document.collection.should be_instance_of(Mongo::Collection)
|
73
66
|
@document.collection.name.should == 'foobar'
|
74
67
|
end
|
68
|
+
|
69
|
+
should 'allow extensions to Document to be appended' do
|
70
|
+
module Extension; def test_this_extension; end end
|
71
|
+
MongoMapper::Document.append_extensions(Extension)
|
72
|
+
article = Doc()
|
73
|
+
article.should respond_to(:test_this_extension)
|
74
|
+
end
|
75
|
+
|
76
|
+
should 'add appended extensions to classes that include Document before they are added' do
|
77
|
+
module Extension; def test_this_extension; end end
|
78
|
+
article = Doc()
|
79
|
+
MongoMapper::Document.append_extensions(Extension)
|
80
|
+
article.should respond_to(:test_this_extension)
|
81
|
+
end
|
82
|
+
|
83
|
+
should 'allow inclusions to Document to be appended' do
|
84
|
+
module Inclusion; def test_this_inclusion; end end
|
85
|
+
MongoMapper::Document.append_inclusions(Inclusion)
|
86
|
+
article = Doc()
|
87
|
+
article.new.should respond_to(:test_this_inclusion)
|
88
|
+
end
|
89
|
+
|
90
|
+
should 'add appended inclusions to classes that include Document before they are added' do
|
91
|
+
module Inclusion; def test_this_inclusion; end end
|
92
|
+
article = Doc()
|
93
|
+
MongoMapper::Document.append_inclusions(Inclusion)
|
94
|
+
article.new.should respond_to(:test_this_inclusion)
|
95
|
+
end
|
75
96
|
end # Document class
|
76
97
|
|
77
98
|
context "Documents that inherit from other documents" do
|
@@ -96,14 +117,10 @@ class DocumentTest < Test::Unit::TestCase
|
|
96
117
|
|
97
118
|
context "An instance of a document" do
|
98
119
|
setup do
|
99
|
-
@document =
|
100
|
-
include MongoMapper::Document
|
101
|
-
set_collection_name 'test'
|
102
|
-
|
120
|
+
@document = Doc do
|
103
121
|
key :name, String
|
104
122
|
key :age, Integer
|
105
123
|
end
|
106
|
-
@document.collection.remove
|
107
124
|
end
|
108
125
|
|
109
126
|
should "have access to logger" do
|
@@ -137,13 +154,9 @@ class DocumentTest < Test::Unit::TestCase
|
|
137
154
|
end
|
138
155
|
|
139
156
|
should "set self to the root document on embedded documents" do
|
140
|
-
klass =
|
141
|
-
|
142
|
-
end
|
157
|
+
klass = Doc()
|
158
|
+
pets = EDoc()
|
143
159
|
|
144
|
-
pets = Class.new do
|
145
|
-
include MongoMapper::EmbeddedDocument
|
146
|
-
end
|
147
160
|
klass.many :pets, :class => pets
|
148
161
|
|
149
162
|
doc = klass.new(:pets => [{}])
|
@@ -183,6 +196,7 @@ class DocumentTest < Test::Unit::TestCase
|
|
183
196
|
setup do
|
184
197
|
@oid = Mongo::ObjectID.new
|
185
198
|
end
|
199
|
+
|
186
200
|
should "be equal if id and class are the same" do
|
187
201
|
(@document.new('_id' => @oid) == @document.new('_id' => @oid)).should be(true)
|
188
202
|
end
|
@@ -192,12 +206,8 @@ class DocumentTest < Test::Unit::TestCase
|
|
192
206
|
end
|
193
207
|
|
194
208
|
should "not be equal if id same but class different" do
|
195
|
-
|
196
|
-
|
197
|
-
set_collection_name 'test'
|
198
|
-
end
|
199
|
-
|
200
|
-
(@document.new('_id' => @oid) == @another_document.new('_id' => @oid)).should be(false)
|
209
|
+
another_document = Doc()
|
210
|
+
(@document.new('_id' => @oid) == another_document.new('_id' => @oid)).should be(false)
|
201
211
|
end
|
202
212
|
end
|
203
213
|
end # instance of a document
|
@@ -35,9 +35,7 @@ end
|
|
35
35
|
class EmbeddedDocumentTest < Test::Unit::TestCase
|
36
36
|
context "Including MongoMapper::EmbeddedDocument in a class" do
|
37
37
|
setup do
|
38
|
-
@klass =
|
39
|
-
include MongoMapper::EmbeddedDocument
|
40
|
-
end
|
38
|
+
@klass = EDoc()
|
41
39
|
end
|
42
40
|
|
43
41
|
should "give class access to logger" do
|
@@ -89,29 +87,16 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
|
|
89
87
|
end
|
90
88
|
end
|
91
89
|
|
92
|
-
context "looking up type constants" do
|
93
|
-
should "not raise an error" do
|
94
|
-
klass = Class.new do
|
95
|
-
include MongoMapper::EmbeddedDocument
|
96
|
-
key :file, Binary
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
90
|
context "parent_model" do
|
102
91
|
should "be nil if none of parents ancestors include EmbeddedDocument" do
|
103
92
|
parent = Class.new
|
104
|
-
document = Class.new(parent)
|
105
|
-
include MongoMapper::EmbeddedDocument
|
106
|
-
end
|
93
|
+
document = Class.new(parent) { include MongoMapper::EmbeddedDocument }
|
107
94
|
document.parent_model.should be_nil
|
108
95
|
end
|
109
96
|
|
110
97
|
should "work when other modules have been included" do
|
111
98
|
grandparent = Class.new
|
112
|
-
parent = Class.new
|
113
|
-
include MongoMapper::EmbeddedDocument
|
114
|
-
end
|
99
|
+
parent = Class.new(grandparent) { include MongoMapper::EmbeddedDocument }
|
115
100
|
|
116
101
|
example_module = Module.new
|
117
102
|
document = Class.new(parent) do
|
@@ -130,9 +115,7 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
|
|
130
115
|
|
131
116
|
context "defining a key" do
|
132
117
|
setup do
|
133
|
-
@document =
|
134
|
-
include MongoMapper::EmbeddedDocument
|
135
|
-
end
|
118
|
+
@document = EDoc()
|
136
119
|
end
|
137
120
|
|
138
121
|
should "work with name" do
|
@@ -226,8 +209,7 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
|
|
226
209
|
|
227
210
|
context "#inspect" do
|
228
211
|
setup do
|
229
|
-
@document =
|
230
|
-
include MongoMapper::Document
|
212
|
+
@document = Doc do
|
231
213
|
key :animals
|
232
214
|
end
|
233
215
|
end
|
@@ -252,9 +234,7 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
|
|
252
234
|
|
253
235
|
context "Applying default values for keys" do
|
254
236
|
setup do
|
255
|
-
@document =
|
256
|
-
include MongoMapper::EmbeddedDocument
|
257
|
-
|
237
|
+
@document = EDoc do
|
258
238
|
key :name, String, :default => 'foo'
|
259
239
|
key :age, Integer, :default => 20
|
260
240
|
key :net_worth, Float, :default => 100.00
|
@@ -299,9 +279,7 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
|
|
299
279
|
|
300
280
|
context "An instance of an embedded document" do
|
301
281
|
setup do
|
302
|
-
@document =
|
303
|
-
include MongoMapper::EmbeddedDocument
|
304
|
-
|
282
|
+
@document = EDoc do
|
305
283
|
key :name, String
|
306
284
|
key :age, Integer
|
307
285
|
end
|
@@ -398,8 +376,7 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
|
|
398
376
|
|
399
377
|
context "initialized when _type key present" do
|
400
378
|
setup do
|
401
|
-
::FooBar =
|
402
|
-
include MongoMapper::EmbeddedDocument
|
379
|
+
::FooBar = EDoc do
|
403
380
|
key :_type, String
|
404
381
|
end
|
405
382
|
end
|
@@ -580,18 +557,8 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
|
|
580
557
|
doc.instance_variable_get("@foo").should == []
|
581
558
|
end
|
582
559
|
|
583
|
-
should "not set instance variable if frozen" do
|
584
|
-
@document.key :foo, Array
|
585
|
-
doc = @document.new
|
586
|
-
doc.instance_variable_get("@foo").should be_nil
|
587
|
-
doc.freeze
|
588
|
-
doc.foo
|
589
|
-
doc.instance_variable_get("@foo").should be_nil
|
590
|
-
end
|
591
|
-
|
592
560
|
should "be overrideable by modules" do
|
593
|
-
@document =
|
594
|
-
include MongoMapper::Document
|
561
|
+
@document = Doc do
|
595
562
|
key :other_child, String
|
596
563
|
end
|
597
564
|
|
@@ -665,8 +632,7 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
|
|
665
632
|
end
|
666
633
|
|
667
634
|
should "be overrideable by modules" do
|
668
|
-
@document =
|
669
|
-
include MongoMapper::Document
|
635
|
+
@document = Doc do
|
670
636
|
key :other_child, String
|
671
637
|
end
|
672
638
|
|
@@ -699,19 +665,16 @@ class EmbeddedDocumentTest < Test::Unit::TestCase
|
|
699
665
|
@oid = Mongo::ObjectID.new
|
700
666
|
end
|
701
667
|
should "be equal if id and class are the same" do
|
702
|
-
(@document.new('_id' => @oid) == @document.new('_id' => @oid)).should
|
668
|
+
(@document.new('_id' => @oid) == @document.new('_id' => @oid)).should be_true
|
703
669
|
end
|
704
670
|
|
705
671
|
should "not be equal if class same but id different" do
|
706
|
-
(@document.new('_id' => @oid) == @document.new('_id' => Mongo::ObjectID.new)).should
|
672
|
+
(@document.new('_id' => @oid) == @document.new('_id' => Mongo::ObjectID.new)).should be_false
|
707
673
|
end
|
708
674
|
|
709
675
|
should "not be equal if id same but class different" do
|
710
|
-
|
711
|
-
|
712
|
-
end
|
713
|
-
|
714
|
-
(@document.new('_id' => @oid) == @another_document.new('_id' => @oid)).should be(false)
|
676
|
+
another_document = Doc()
|
677
|
+
(@document.new('_id' => @oid) == another_document.new('_id' => @oid)).should be_false
|
715
678
|
end
|
716
679
|
end
|
717
680
|
end # instance of a embedded document
|
@@ -30,6 +30,13 @@ class FinderOptionsTest < Test::Unit::TestCase
|
|
30
30
|
}
|
31
31
|
end
|
32
32
|
|
33
|
+
should "automatically add _type to query if model is single collection inherited" do
|
34
|
+
FinderOptions.new(Enter, :foo => 'bar').criteria.should == {
|
35
|
+
:foo => 'bar',
|
36
|
+
:_type => 'Enter'
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
33
40
|
%w{gt lt gte lte ne in nin mod size where exists}.each do |operator|
|
34
41
|
should "convert #{operator} conditions" do
|
35
42
|
FinderOptions.new(Room, :age.send(operator) => 21).criteria.should == {
|
@@ -38,13 +45,6 @@ class FinderOptionsTest < Test::Unit::TestCase
|
|
38
45
|
end
|
39
46
|
end
|
40
47
|
|
41
|
-
should "automatically add _type to query if model is single collection inherited" do
|
42
|
-
FinderOptions.new(Enter, :foo => 'bar').criteria.should == {
|
43
|
-
:foo => 'bar',
|
44
|
-
:_type => 'Enter'
|
45
|
-
}
|
46
|
-
end
|
47
|
-
|
48
48
|
should "work with simple criteria" do
|
49
49
|
FinderOptions.new(Room, :foo => 'bar').criteria.should == {
|
50
50
|
:foo => 'bar'
|
@@ -88,6 +88,19 @@ class FinderOptionsTest < Test::Unit::TestCase
|
|
88
88
|
FinderOptions.new(Message, :room_id => id).criteria.should == {:room_id => id}
|
89
89
|
end
|
90
90
|
|
91
|
+
should "convert times to utc if they aren't already" do
|
92
|
+
time = Time.now.in_time_zone('Indiana (East)')
|
93
|
+
criteria = FinderOptions.new(Room, :created_at => time).criteria
|
94
|
+
criteria[:created_at].utc?.should be_true
|
95
|
+
end
|
96
|
+
|
97
|
+
should "not funk with times already in utc" do
|
98
|
+
time = Time.now.utc
|
99
|
+
criteria = FinderOptions.new(Room, :created_at => time).criteria
|
100
|
+
criteria[:created_at].utc?.should be_true
|
101
|
+
criteria[:created_at].should == time
|
102
|
+
end
|
103
|
+
|
91
104
|
should "use $in for arrays" do
|
92
105
|
FinderOptions.new(Room, :foo => [1,2,3]).criteria.should == {
|
93
106
|
:foo => {'$in' => [1,2,3]}
|
data/test/unit/test_key.rb
CHANGED
@@ -82,10 +82,7 @@ class KeyTest < Test::Unit::TestCase
|
|
82
82
|
end
|
83
83
|
|
84
84
|
should "know if it is a embedded_document" do
|
85
|
-
|
86
|
-
include MongoMapper::EmbeddedDocument
|
87
|
-
end
|
88
|
-
Key.new(:name, klass).embeddable?.should be_true
|
85
|
+
Key.new(:name, EDoc()).embeddable?.should be_true
|
89
86
|
end
|
90
87
|
|
91
88
|
should "know if it is not a embedded_document" do
|
@@ -62,6 +62,12 @@ class PaginationTest < Test::Unit::TestCase
|
|
62
62
|
should "alias offset to skip" do
|
63
63
|
PaginationProxy.new(25, 2, 10).offset.should == 10
|
64
64
|
end
|
65
|
+
|
66
|
+
should "return true for === Array" do
|
67
|
+
collection = PaginationProxy.new(25, 2, 10)
|
68
|
+
collection.subject = [1, 2]
|
69
|
+
collection.should === Array
|
70
|
+
end
|
65
71
|
|
66
72
|
context "previous_page" do
|
67
73
|
should "be nil if current page 1" do
|
@@ -22,7 +22,10 @@ class TestRailsCompatibility < Test::Unit::TestCase
|
|
22
22
|
context "EmbeddedDocument" do
|
23
23
|
should "alias many to has_many" do
|
24
24
|
FirstItem.should respond_to(:has_many)
|
25
|
-
|
25
|
+
end
|
26
|
+
|
27
|
+
should "alias one to has_one" do
|
28
|
+
FirstItem.should respond_to(:has_one)
|
26
29
|
end
|
27
30
|
|
28
31
|
should "have column names" do
|
data/test/unit/test_support.rb
CHANGED
@@ -167,6 +167,10 @@ class SupportTest < Test::Unit::TestCase
|
|
167
167
|
ObjectId.to_mongo(nil).should be_nil
|
168
168
|
end
|
169
169
|
|
170
|
+
should "return nil if blank string" do
|
171
|
+
ObjectId.to_mongo('').should be_nil
|
172
|
+
end
|
173
|
+
|
170
174
|
should "return value if object id" do
|
171
175
|
id = Mongo::ObjectID.new
|
172
176
|
ObjectId.to_mongo(id).should be(id)
|
@@ -3,8 +3,7 @@ require 'test_helper'
|
|
3
3
|
class TimeZonesTest < Test::Unit::TestCase
|
4
4
|
context "An instance of an embedded document" do
|
5
5
|
setup do
|
6
|
-
@document =
|
7
|
-
include MongoMapper::EmbeddedDocument
|
6
|
+
@document = EDoc do
|
8
7
|
key :name, String
|
9
8
|
key :created_at, Time
|
10
9
|
end
|
@@ -2,14 +2,9 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class ValidationsTest < Test::Unit::TestCase
|
4
4
|
context "Validations" do
|
5
|
-
|
6
5
|
context "on a Document" do
|
7
|
-
|
8
6
|
setup do
|
9
|
-
@document =
|
10
|
-
include MongoMapper::Document
|
11
|
-
set_collection_name 'test'
|
12
|
-
end
|
7
|
+
@document = Doc()
|
13
8
|
end
|
14
9
|
|
15
10
|
context "Validating acceptance of" do
|
@@ -240,11 +235,8 @@ class ValidationsTest < Test::Unit::TestCase
|
|
240
235
|
end # End on a Document
|
241
236
|
|
242
237
|
context "On an EmbeddedDocument" do
|
243
|
-
|
244
238
|
setup do
|
245
|
-
@embedded_doc =
|
246
|
-
include MongoMapper::EmbeddedDocument
|
247
|
-
end
|
239
|
+
@embedded_doc = EDoc()
|
248
240
|
end
|
249
241
|
|
250
242
|
context "Validating acceptance of" do
|
@@ -478,10 +470,7 @@ class ValidationsTest < Test::Unit::TestCase
|
|
478
470
|
|
479
471
|
context "Adding validation errors" do
|
480
472
|
setup do
|
481
|
-
@document =
|
482
|
-
include MongoMapper::Document
|
483
|
-
set_collection_name 'test'
|
484
|
-
|
473
|
+
@document = Doc do
|
485
474
|
key :action, String
|
486
475
|
def action_present
|
487
476
|
errors.add(:action, 'is invalid') if action.blank?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_mapper-unstable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2010.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-04 00:00:00 -05:00
|
13
13
|
default_executable: mmconsole
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.18.
|
33
|
+
version: 0.18.2
|
34
34
|
version:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: jnunemaker-validatable
|
@@ -104,11 +104,13 @@ files:
|
|
104
104
|
- lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb
|
105
105
|
- lib/mongo_mapper/associations/belongs_to_proxy.rb
|
106
106
|
- lib/mongo_mapper/associations/collection.rb
|
107
|
+
- lib/mongo_mapper/associations/in_array_proxy.rb
|
107
108
|
- lib/mongo_mapper/associations/many_documents_as_proxy.rb
|
108
109
|
- lib/mongo_mapper/associations/many_documents_proxy.rb
|
109
110
|
- lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
|
110
111
|
- lib/mongo_mapper/associations/many_embedded_proxy.rb
|
111
112
|
- lib/mongo_mapper/associations/many_polymorphic_proxy.rb
|
113
|
+
- lib/mongo_mapper/associations/one_proxy.rb
|
112
114
|
- lib/mongo_mapper/associations/proxy.rb
|
113
115
|
- lib/mongo_mapper/callbacks.rb
|
114
116
|
- lib/mongo_mapper/dirty.rb
|
@@ -117,7 +119,7 @@ files:
|
|
117
119
|
- lib/mongo_mapper/embedded_document.rb
|
118
120
|
- lib/mongo_mapper/finder_options.rb
|
119
121
|
- lib/mongo_mapper/key.rb
|
120
|
-
- lib/mongo_mapper/
|
122
|
+
- lib/mongo_mapper/mongo_mapper.rb
|
121
123
|
- lib/mongo_mapper/pagination.rb
|
122
124
|
- lib/mongo_mapper/rails_compatibility/document.rb
|
123
125
|
- lib/mongo_mapper/rails_compatibility/embedded_document.rb
|
@@ -130,11 +132,13 @@ files:
|
|
130
132
|
- test/NOTE_ON_TESTING
|
131
133
|
- test/functional/associations/test_belongs_to_polymorphic_proxy.rb
|
132
134
|
- test/functional/associations/test_belongs_to_proxy.rb
|
135
|
+
- test/functional/associations/test_in_array_proxy.rb
|
133
136
|
- test/functional/associations/test_many_documents_as_proxy.rb
|
134
137
|
- test/functional/associations/test_many_documents_proxy.rb
|
135
138
|
- test/functional/associations/test_many_embedded_polymorphic_proxy.rb
|
136
139
|
- test/functional/associations/test_many_embedded_proxy.rb
|
137
140
|
- test/functional/associations/test_many_polymorphic_proxy.rb
|
141
|
+
- test/functional/associations/test_one_proxy.rb
|
138
142
|
- test/functional/test_associations.rb
|
139
143
|
- test/functional/test_binary.rb
|
140
144
|
- test/functional/test_callbacks.rb
|
@@ -142,6 +146,7 @@ files:
|
|
142
146
|
- test/functional/test_document.rb
|
143
147
|
- test/functional/test_embedded_document.rb
|
144
148
|
- test/functional/test_logger.rb
|
149
|
+
- test/functional/test_modifiers.rb
|
145
150
|
- test/functional/test_pagination.rb
|
146
151
|
- test/functional/test_rails_compatibility.rb
|
147
152
|
- test/functional/test_string_id_compatibility.rb
|
@@ -159,7 +164,6 @@ files:
|
|
159
164
|
- test/unit/test_finder_options.rb
|
160
165
|
- test/unit/test_key.rb
|
161
166
|
- test/unit/test_mongo_mapper.rb
|
162
|
-
- test/unit/test_observing.rb
|
163
167
|
- test/unit/test_pagination.rb
|
164
168
|
- test/unit/test_rails_compatibility.rb
|
165
169
|
- test/unit/test_serializations.rb
|
@@ -205,7 +209,6 @@ test_files:
|
|
205
209
|
- test/unit/associations/test_proxy.rb
|
206
210
|
- test/unit/associations/test_base.rb
|
207
211
|
- test/unit/test_time_zones.rb
|
208
|
-
- test/unit/test_observing.rb
|
209
212
|
- test/unit/test_rails_compatibility.rb
|
210
213
|
- test/unit/test_validations.rb
|
211
214
|
- test/unit/test_mongo_mapper.rb
|
@@ -214,16 +217,19 @@ test_files:
|
|
214
217
|
- test/test_helper.rb
|
215
218
|
- test/support/custom_matchers.rb
|
216
219
|
- test/support/timing.rb
|
220
|
+
- test/functional/test_modifiers.rb
|
217
221
|
- test/functional/test_embedded_document.rb
|
218
222
|
- test/functional/test_string_id_compatibility.rb
|
219
223
|
- test/functional/test_associations.rb
|
220
224
|
- test/functional/associations/test_belongs_to_proxy.rb
|
225
|
+
- test/functional/associations/test_in_array_proxy.rb
|
221
226
|
- test/functional/associations/test_many_documents_proxy.rb
|
222
227
|
- test/functional/associations/test_many_embedded_proxy.rb
|
223
228
|
- test/functional/associations/test_many_documents_as_proxy.rb
|
224
229
|
- test/functional/associations/test_many_embedded_polymorphic_proxy.rb
|
225
230
|
- test/functional/associations/test_many_polymorphic_proxy.rb
|
226
231
|
- test/functional/associations/test_belongs_to_polymorphic_proxy.rb
|
232
|
+
- test/functional/associations/test_one_proxy.rb
|
227
233
|
- test/functional/test_binary.rb
|
228
234
|
- test/functional/test_dirty.rb
|
229
235
|
- test/functional/test_callbacks.rb
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'observer'
|
2
|
-
require 'singleton'
|
3
|
-
require 'set'
|
4
|
-
|
5
|
-
module MongoMapper
|
6
|
-
module Observing #:nodoc:
|
7
|
-
def self.included(model)
|
8
|
-
model.class_eval do
|
9
|
-
extend Observable
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class Observer
|
15
|
-
include Singleton
|
16
|
-
|
17
|
-
class << self
|
18
|
-
def observe(*models)
|
19
|
-
models.flatten!
|
20
|
-
models.collect! { |model| model.is_a?(Symbol) ? model.to_s.camelize.constantize : model }
|
21
|
-
define_method(:observed_classes) { Set.new(models) }
|
22
|
-
end
|
23
|
-
|
24
|
-
def observed_class
|
25
|
-
if observed_class_name = name[/(.*)Observer/, 1]
|
26
|
-
observed_class_name.constantize
|
27
|
-
else
|
28
|
-
nil
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def initialize
|
34
|
-
Set.new(observed_classes).each { |klass| add_observer! klass }
|
35
|
-
end
|
36
|
-
|
37
|
-
def update(observed_method, object) #:nodoc:
|
38
|
-
send(observed_method, object) if respond_to?(observed_method)
|
39
|
-
end
|
40
|
-
|
41
|
-
protected
|
42
|
-
def observed_classes
|
43
|
-
Set.new([self.class.observed_class].compact.flatten)
|
44
|
-
end
|
45
|
-
|
46
|
-
def add_observer!(klass)
|
47
|
-
klass.add_observer(self)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|