mongo_mapper_ign 0.7.7 → 0.7.8
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -20
- data/README.rdoc +34 -34
- data/bin/mmconsole +60 -60
- data/lib/mongo_mapper.rb +123 -123
- data/lib/mongo_mapper/document.rb +292 -292
- data/lib/mongo_mapper/embedded_document.rb +71 -71
- data/lib/mongo_mapper/plugins.rb +36 -36
- data/lib/mongo_mapper/plugins/associations.rb +115 -115
- data/lib/mongo_mapper/plugins/associations/base.rb +124 -124
- data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +31 -31
- data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +26 -26
- data/lib/mongo_mapper/plugins/associations/collection.rb +21 -21
- data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +39 -39
- data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +160 -144
- data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +29 -29
- data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +130 -130
- data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +32 -32
- data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +24 -24
- data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +14 -14
- data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +42 -42
- data/lib/mongo_mapper/plugins/associations/one_proxy.rb +70 -70
- data/lib/mongo_mapper/plugins/associations/proxy.rb +125 -125
- data/lib/mongo_mapper/plugins/callbacks.rb +241 -241
- data/lib/mongo_mapper/plugins/clone.rb +13 -13
- data/lib/mongo_mapper/plugins/descendants.rb +16 -16
- data/lib/mongo_mapper/plugins/dirty.rb +119 -119
- data/lib/mongo_mapper/plugins/equality.rb +23 -23
- data/lib/mongo_mapper/plugins/identity_map.rb +123 -123
- data/lib/mongo_mapper/plugins/inspect.rb +14 -14
- data/lib/mongo_mapper/plugins/keys.rb +322 -322
- data/lib/mongo_mapper/plugins/keys/key.rb +53 -53
- data/lib/mongo_mapper/plugins/logger.rb +17 -17
- data/lib/mongo_mapper/plugins/modifiers.rb +111 -111
- data/lib/mongo_mapper/plugins/pagination.rb +24 -24
- data/lib/mongo_mapper/plugins/pagination/proxy.rb +72 -72
- data/lib/mongo_mapper/plugins/persistence.rb +96 -96
- data/lib/mongo_mapper/plugins/protected.rb +46 -46
- data/lib/mongo_mapper/plugins/rails.rb +57 -57
- data/lib/mongo_mapper/plugins/serialization.rb +92 -92
- data/lib/mongo_mapper/plugins/serialization/array.rb +56 -56
- data/lib/mongo_mapper/plugins/serialization/xml_serializer.rb +239 -239
- data/lib/mongo_mapper/plugins/timestamps.rb +21 -21
- data/lib/mongo_mapper/plugins/userstamps.rb +14 -14
- data/lib/mongo_mapper/plugins/validations.rb +46 -46
- data/lib/mongo_mapper/query.rb +28 -28
- data/lib/mongo_mapper/support.rb +197 -197
- data/lib/mongo_mapper/support/descendant_appends.rb +46 -46
- data/lib/mongo_mapper/support/find.rb +77 -77
- data/lib/mongo_mapper/version.rb +3 -3
- metadata +4 -25
@@ -1,29 +1,29 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
module MongoMapper
|
3
|
-
module Plugins
|
4
|
-
module Associations
|
5
|
-
class ManyDocumentsAsProxy < ManyDocumentsProxy
|
6
|
-
protected
|
7
|
-
def scoped_conditions
|
8
|
-
{type_key_name => owner.class.name, id_key_name => owner.id}
|
9
|
-
end
|
10
|
-
|
11
|
-
def apply_scope(doc)
|
12
|
-
ensure_owner_saved
|
13
|
-
doc[type_key_name] = owner.class.name
|
14
|
-
doc[id_key_name] = owner.id
|
15
|
-
doc
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
def type_key_name
|
20
|
-
"#{options[:as]}_type"
|
21
|
-
end
|
22
|
-
|
23
|
-
def id_key_name
|
24
|
-
"#{options[:as]}_id"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
module MongoMapper
|
3
|
+
module Plugins
|
4
|
+
module Associations
|
5
|
+
class ManyDocumentsAsProxy < ManyDocumentsProxy
|
6
|
+
protected
|
7
|
+
def scoped_conditions
|
8
|
+
{type_key_name => owner.class.name, id_key_name => owner.id}
|
9
|
+
end
|
10
|
+
|
11
|
+
def apply_scope(doc)
|
12
|
+
ensure_owner_saved
|
13
|
+
doc[type_key_name] = owner.class.name
|
14
|
+
doc[id_key_name] = owner.id
|
15
|
+
doc
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def type_key_name
|
20
|
+
"#{options[:as]}_type"
|
21
|
+
end
|
22
|
+
|
23
|
+
def id_key_name
|
24
|
+
"#{options[:as]}_id"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,130 +1,130 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
module MongoMapper
|
3
|
-
module Plugins
|
4
|
-
module Associations
|
5
|
-
class ManyDocumentsProxy < Collection
|
6
|
-
include Support::Find
|
7
|
-
|
8
|
-
def find(*args)
|
9
|
-
options = args.extract_options!
|
10
|
-
klass.find(*args << scoped_options(options))
|
11
|
-
end
|
12
|
-
|
13
|
-
def find!(*args)
|
14
|
-
options = args.extract_options!
|
15
|
-
klass.find!(*args << scoped_options(options))
|
16
|
-
end
|
17
|
-
|
18
|
-
def paginate(options)
|
19
|
-
klass.paginate(scoped_options(options))
|
20
|
-
end
|
21
|
-
|
22
|
-
def all(options={})
|
23
|
-
klass.all(scoped_options(options))
|
24
|
-
end
|
25
|
-
|
26
|
-
def first(options={})
|
27
|
-
klass.first(scoped_options(options))
|
28
|
-
end
|
29
|
-
|
30
|
-
def last(options={})
|
31
|
-
klass.last(scoped_options(options))
|
32
|
-
end
|
33
|
-
|
34
|
-
def count(options={})
|
35
|
-
klass.count(scoped_options(options))
|
36
|
-
end
|
37
|
-
|
38
|
-
def replace(docs)
|
39
|
-
load_target
|
40
|
-
target.map(&:destroy)
|
41
|
-
docs.each { |doc| prepare(doc).save }
|
42
|
-
reset
|
43
|
-
end
|
44
|
-
|
45
|
-
def <<(*docs)
|
46
|
-
ensure_owner_saved
|
47
|
-
flatten_deeper(docs).each { |doc| prepare(doc).save }
|
48
|
-
reset
|
49
|
-
end
|
50
|
-
alias_method :push, :<<
|
51
|
-
alias_method :concat, :<<
|
52
|
-
|
53
|
-
def build(attrs={})
|
54
|
-
doc = klass.new(attrs)
|
55
|
-
apply_scope(doc)
|
56
|
-
@target ||= [] unless loaded?
|
57
|
-
@target << doc
|
58
|
-
doc
|
59
|
-
end
|
60
|
-
|
61
|
-
def create(attrs={})
|
62
|
-
doc = klass.new(attrs)
|
63
|
-
apply_scope(doc).save
|
64
|
-
reset
|
65
|
-
doc
|
66
|
-
end
|
67
|
-
|
68
|
-
def create!(attrs={})
|
69
|
-
doc = klass.new(attrs)
|
70
|
-
apply_scope(doc).save!
|
71
|
-
reset
|
72
|
-
doc
|
73
|
-
end
|
74
|
-
|
75
|
-
def destroy_all(options={})
|
76
|
-
all(options).map(&:destroy)
|
77
|
-
reset
|
78
|
-
end
|
79
|
-
|
80
|
-
def delete_all(options={})
|
81
|
-
klass.delete_all(options.merge(scoped_conditions))
|
82
|
-
reset
|
83
|
-
end
|
84
|
-
|
85
|
-
def nullify
|
86
|
-
criteria = Query.new(klass, scoped_conditions).criteria
|
87
|
-
all(criteria).each do |doc|
|
88
|
-
doc.update_attributes(self.foreign_key => nil)
|
89
|
-
end
|
90
|
-
reset
|
91
|
-
end
|
92
|
-
|
93
|
-
def save_to_collection(options = {})
|
94
|
-
@target.each { |doc| doc.save(options) } if @target
|
95
|
-
end
|
96
|
-
|
97
|
-
protected
|
98
|
-
def scoped_conditions
|
99
|
-
{self.foreign_key => owner.id}
|
100
|
-
end
|
101
|
-
|
102
|
-
def scoped_options(options)
|
103
|
-
association.query_options.merge(options).merge(scoped_conditions)
|
104
|
-
end
|
105
|
-
|
106
|
-
def find_target
|
107
|
-
all
|
108
|
-
end
|
109
|
-
|
110
|
-
def ensure_owner_saved
|
111
|
-
owner.save if owner.new?
|
112
|
-
end
|
113
|
-
|
114
|
-
def prepare(doc)
|
115
|
-
klass === doc ? apply_scope(doc) : build(doc)
|
116
|
-
end
|
117
|
-
|
118
|
-
def apply_scope(doc)
|
119
|
-
ensure_owner_saved
|
120
|
-
doc[foreign_key] = owner.id
|
121
|
-
doc
|
122
|
-
end
|
123
|
-
|
124
|
-
def foreign_key
|
125
|
-
options[:foreign_key] || owner.class.name.to_s.underscore.gsub("/", "_") + "_id"
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
module MongoMapper
|
3
|
+
module Plugins
|
4
|
+
module Associations
|
5
|
+
class ManyDocumentsProxy < Collection
|
6
|
+
include Support::Find
|
7
|
+
|
8
|
+
def find(*args)
|
9
|
+
options = args.extract_options!
|
10
|
+
klass.find(*args << scoped_options(options))
|
11
|
+
end
|
12
|
+
|
13
|
+
def find!(*args)
|
14
|
+
options = args.extract_options!
|
15
|
+
klass.find!(*args << scoped_options(options))
|
16
|
+
end
|
17
|
+
|
18
|
+
def paginate(options)
|
19
|
+
klass.paginate(scoped_options(options))
|
20
|
+
end
|
21
|
+
|
22
|
+
def all(options={})
|
23
|
+
klass.all(scoped_options(options))
|
24
|
+
end
|
25
|
+
|
26
|
+
def first(options={})
|
27
|
+
klass.first(scoped_options(options))
|
28
|
+
end
|
29
|
+
|
30
|
+
def last(options={})
|
31
|
+
klass.last(scoped_options(options))
|
32
|
+
end
|
33
|
+
|
34
|
+
def count(options={})
|
35
|
+
klass.count(scoped_options(options))
|
36
|
+
end
|
37
|
+
|
38
|
+
def replace(docs)
|
39
|
+
load_target
|
40
|
+
target.map(&:destroy)
|
41
|
+
docs.each { |doc| prepare(doc).save }
|
42
|
+
reset
|
43
|
+
end
|
44
|
+
|
45
|
+
def <<(*docs)
|
46
|
+
ensure_owner_saved
|
47
|
+
flatten_deeper(docs).each { |doc| prepare(doc).save }
|
48
|
+
reset
|
49
|
+
end
|
50
|
+
alias_method :push, :<<
|
51
|
+
alias_method :concat, :<<
|
52
|
+
|
53
|
+
def build(attrs={})
|
54
|
+
doc = klass.new(attrs)
|
55
|
+
apply_scope(doc)
|
56
|
+
@target ||= [] unless loaded?
|
57
|
+
@target << doc
|
58
|
+
doc
|
59
|
+
end
|
60
|
+
|
61
|
+
def create(attrs={})
|
62
|
+
doc = klass.new(attrs)
|
63
|
+
apply_scope(doc).save
|
64
|
+
reset
|
65
|
+
doc
|
66
|
+
end
|
67
|
+
|
68
|
+
def create!(attrs={})
|
69
|
+
doc = klass.new(attrs)
|
70
|
+
apply_scope(doc).save!
|
71
|
+
reset
|
72
|
+
doc
|
73
|
+
end
|
74
|
+
|
75
|
+
def destroy_all(options={})
|
76
|
+
all(options).map(&:destroy)
|
77
|
+
reset
|
78
|
+
end
|
79
|
+
|
80
|
+
def delete_all(options={})
|
81
|
+
klass.delete_all(options.merge(scoped_conditions))
|
82
|
+
reset
|
83
|
+
end
|
84
|
+
|
85
|
+
def nullify
|
86
|
+
criteria = Query.new(klass, scoped_conditions).criteria
|
87
|
+
all(criteria).each do |doc|
|
88
|
+
doc.update_attributes(self.foreign_key => nil)
|
89
|
+
end
|
90
|
+
reset
|
91
|
+
end
|
92
|
+
|
93
|
+
def save_to_collection(options = {})
|
94
|
+
@target.each { |doc| doc.save(options) } if @target
|
95
|
+
end
|
96
|
+
|
97
|
+
protected
|
98
|
+
def scoped_conditions
|
99
|
+
{self.foreign_key => owner.id}
|
100
|
+
end
|
101
|
+
|
102
|
+
def scoped_options(options)
|
103
|
+
association.query_options.merge(options).merge(scoped_conditions)
|
104
|
+
end
|
105
|
+
|
106
|
+
def find_target
|
107
|
+
all
|
108
|
+
end
|
109
|
+
|
110
|
+
def ensure_owner_saved
|
111
|
+
owner.save if owner.new?
|
112
|
+
end
|
113
|
+
|
114
|
+
def prepare(doc)
|
115
|
+
klass === doc ? apply_scope(doc) : build(doc)
|
116
|
+
end
|
117
|
+
|
118
|
+
def apply_scope(doc)
|
119
|
+
ensure_owner_saved
|
120
|
+
doc[foreign_key] = owner.id
|
121
|
+
doc
|
122
|
+
end
|
123
|
+
|
124
|
+
def foreign_key
|
125
|
+
options[:foreign_key] || owner.class.name.to_s.underscore.gsub("/", "_") + "_id"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -1,32 +1,32 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
module MongoMapper
|
3
|
-
module Plugins
|
4
|
-
module Associations
|
5
|
-
class ManyEmbeddedPolymorphicProxy < EmbeddedCollection
|
6
|
-
def replace(values)
|
7
|
-
@_values = values.map do |v|
|
8
|
-
v.respond_to?(:attributes) ? v.attributes.merge(association.type_key_name => v.class.name) : v
|
9
|
-
end
|
10
|
-
reset
|
11
|
-
end
|
12
|
-
|
13
|
-
protected
|
14
|
-
def find_target
|
15
|
-
(@_values || []).map do |hash|
|
16
|
-
child = polymorphic_class(hash).load(hash)
|
17
|
-
assign_references(child)
|
18
|
-
child
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def polymorphic_class(doc)
|
23
|
-
if class_name = doc[association.type_key_name]
|
24
|
-
class_name.constantize
|
25
|
-
else
|
26
|
-
klass
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
module MongoMapper
|
3
|
+
module Plugins
|
4
|
+
module Associations
|
5
|
+
class ManyEmbeddedPolymorphicProxy < EmbeddedCollection
|
6
|
+
def replace(values)
|
7
|
+
@_values = values.map do |v|
|
8
|
+
v.respond_to?(:attributes) ? v.attributes.merge(association.type_key_name => v.class.name) : v
|
9
|
+
end
|
10
|
+
reset
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
def find_target
|
15
|
+
(@_values || []).map do |hash|
|
16
|
+
child = polymorphic_class(hash).load(hash)
|
17
|
+
assign_references(child)
|
18
|
+
child
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def polymorphic_class(doc)
|
23
|
+
if class_name = doc[association.type_key_name]
|
24
|
+
class_name.constantize
|
25
|
+
else
|
26
|
+
klass
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,24 +1,24 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
module MongoMapper
|
3
|
-
module Plugins
|
4
|
-
module Associations
|
5
|
-
class ManyEmbeddedProxy < EmbeddedCollection
|
6
|
-
def replace(values)
|
7
|
-
@_values = values.map do |v|
|
8
|
-
v.respond_to?(:attributes) ? v.attributes : v
|
9
|
-
end
|
10
|
-
reset
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
def find_target
|
15
|
-
(@_values || []).map do |attrs|
|
16
|
-
klass.load(attrs).tap do |child|
|
17
|
-
assign_references(child)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
module MongoMapper
|
3
|
+
module Plugins
|
4
|
+
module Associations
|
5
|
+
class ManyEmbeddedProxy < EmbeddedCollection
|
6
|
+
def replace(values)
|
7
|
+
@_values = values.map do |v|
|
8
|
+
v.respond_to?(:attributes) ? v.attributes : v
|
9
|
+
end
|
10
|
+
reset
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def find_target
|
15
|
+
(@_values || []).map do |attrs|
|
16
|
+
klass.load(attrs).tap do |child|
|
17
|
+
assign_references(child)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
module MongoMapper
|
3
|
-
module Plugins
|
4
|
-
module Associations
|
5
|
-
class ManyPolymorphicProxy < ManyDocumentsProxy
|
6
|
-
private
|
7
|
-
def apply_scope(doc)
|
8
|
-
doc[association.type_key_name] = doc.class.name
|
9
|
-
super
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
module MongoMapper
|
3
|
+
module Plugins
|
4
|
+
module Associations
|
5
|
+
class ManyPolymorphicProxy < ManyDocumentsProxy
|
6
|
+
private
|
7
|
+
def apply_scope(doc)
|
8
|
+
doc[association.type_key_name] = doc.class.name
|
9
|
+
super
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|