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.
Files changed (50) hide show
  1. data/LICENSE +20 -20
  2. data/README.rdoc +34 -34
  3. data/bin/mmconsole +60 -60
  4. data/lib/mongo_mapper.rb +123 -123
  5. data/lib/mongo_mapper/document.rb +292 -292
  6. data/lib/mongo_mapper/embedded_document.rb +71 -71
  7. data/lib/mongo_mapper/plugins.rb +36 -36
  8. data/lib/mongo_mapper/plugins/associations.rb +115 -115
  9. data/lib/mongo_mapper/plugins/associations/base.rb +124 -124
  10. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +31 -31
  11. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +26 -26
  12. data/lib/mongo_mapper/plugins/associations/collection.rb +21 -21
  13. data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +39 -39
  14. data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +160 -144
  15. data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +29 -29
  16. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +130 -130
  17. data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +32 -32
  18. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +24 -24
  19. data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +14 -14
  20. data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +42 -42
  21. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +70 -70
  22. data/lib/mongo_mapper/plugins/associations/proxy.rb +125 -125
  23. data/lib/mongo_mapper/plugins/callbacks.rb +241 -241
  24. data/lib/mongo_mapper/plugins/clone.rb +13 -13
  25. data/lib/mongo_mapper/plugins/descendants.rb +16 -16
  26. data/lib/mongo_mapper/plugins/dirty.rb +119 -119
  27. data/lib/mongo_mapper/plugins/equality.rb +23 -23
  28. data/lib/mongo_mapper/plugins/identity_map.rb +123 -123
  29. data/lib/mongo_mapper/plugins/inspect.rb +14 -14
  30. data/lib/mongo_mapper/plugins/keys.rb +322 -322
  31. data/lib/mongo_mapper/plugins/keys/key.rb +53 -53
  32. data/lib/mongo_mapper/plugins/logger.rb +17 -17
  33. data/lib/mongo_mapper/plugins/modifiers.rb +111 -111
  34. data/lib/mongo_mapper/plugins/pagination.rb +24 -24
  35. data/lib/mongo_mapper/plugins/pagination/proxy.rb +72 -72
  36. data/lib/mongo_mapper/plugins/persistence.rb +96 -96
  37. data/lib/mongo_mapper/plugins/protected.rb +46 -46
  38. data/lib/mongo_mapper/plugins/rails.rb +57 -57
  39. data/lib/mongo_mapper/plugins/serialization.rb +92 -92
  40. data/lib/mongo_mapper/plugins/serialization/array.rb +56 -56
  41. data/lib/mongo_mapper/plugins/serialization/xml_serializer.rb +239 -239
  42. data/lib/mongo_mapper/plugins/timestamps.rb +21 -21
  43. data/lib/mongo_mapper/plugins/userstamps.rb +14 -14
  44. data/lib/mongo_mapper/plugins/validations.rb +46 -46
  45. data/lib/mongo_mapper/query.rb +28 -28
  46. data/lib/mongo_mapper/support.rb +197 -197
  47. data/lib/mongo_mapper/support/descendant_appends.rb +46 -46
  48. data/lib/mongo_mapper/support/find.rb +77 -77
  49. data/lib/mongo_mapper/version.rb +3 -3
  50. 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