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,42 +1,42 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
module MongoMapper
|
3
|
-
module Plugins
|
4
|
-
module Associations
|
5
|
-
class OneEmbeddedProxy < Proxy
|
6
|
-
undef_method :object_id
|
7
|
-
|
8
|
-
def build(attributes={})
|
9
|
-
@target = klass.new(attributes)
|
10
|
-
assign_references(@target)
|
11
|
-
loaded
|
12
|
-
@target
|
13
|
-
end
|
14
|
-
|
15
|
-
def replace(doc)
|
16
|
-
if doc.respond_to?(:attributes)
|
17
|
-
@target = klass.load(doc.attributes)
|
18
|
-
else
|
19
|
-
@target = klass.load(doc)
|
20
|
-
end
|
21
|
-
assign_references(@target)
|
22
|
-
loaded
|
23
|
-
@target
|
24
|
-
end
|
25
|
-
|
26
|
-
protected
|
27
|
-
|
28
|
-
def find_target
|
29
|
-
if @value
|
30
|
-
klass.load(@value).tap do |child|
|
31
|
-
assign_references(child)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def assign_references(doc)
|
37
|
-
doc._parent_document = owner
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
module MongoMapper
|
3
|
+
module Plugins
|
4
|
+
module Associations
|
5
|
+
class OneEmbeddedProxy < Proxy
|
6
|
+
undef_method :object_id
|
7
|
+
|
8
|
+
def build(attributes={})
|
9
|
+
@target = klass.new(attributes)
|
10
|
+
assign_references(@target)
|
11
|
+
loaded
|
12
|
+
@target
|
13
|
+
end
|
14
|
+
|
15
|
+
def replace(doc)
|
16
|
+
if doc.respond_to?(:attributes)
|
17
|
+
@target = klass.load(doc.attributes)
|
18
|
+
else
|
19
|
+
@target = klass.load(doc)
|
20
|
+
end
|
21
|
+
assign_references(@target)
|
22
|
+
loaded
|
23
|
+
@target
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def find_target
|
29
|
+
if @value
|
30
|
+
klass.load(@value).tap do |child|
|
31
|
+
assign_references(child)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def assign_references(doc)
|
37
|
+
doc._parent_document = owner
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,70 +1,70 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
module MongoMapper
|
3
|
-
module Plugins
|
4
|
-
module Associations
|
5
|
-
class OneProxy < Proxy
|
6
|
-
undef_method :object_id
|
7
|
-
|
8
|
-
def build(attrs={})
|
9
|
-
instantiate_target(:new, attrs)
|
10
|
-
end
|
11
|
-
|
12
|
-
def create(attrs={})
|
13
|
-
instantiate_target(:create, attrs)
|
14
|
-
end
|
15
|
-
|
16
|
-
def create!(attrs={})
|
17
|
-
instantiate_target(:create!, attrs)
|
18
|
-
end
|
19
|
-
|
20
|
-
def replace(doc)
|
21
|
-
load_target
|
22
|
-
|
23
|
-
if !target.nil? && target != doc
|
24
|
-
if options[:dependent] && !target.new?
|
25
|
-
case options[:dependent]
|
26
|
-
when :delete
|
27
|
-
target.delete
|
28
|
-
when :destroy
|
29
|
-
target.destroy
|
30
|
-
when :nullify
|
31
|
-
target[foreign_key] = nil
|
32
|
-
target.save
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
reset
|
38
|
-
|
39
|
-
unless doc.nil?
|
40
|
-
owner.save if owner.new?
|
41
|
-
doc = klass.new(doc) unless klass === doc
|
42
|
-
doc[foreign_key] = owner.id
|
43
|
-
doc.save if doc.new?
|
44
|
-
loaded
|
45
|
-
@target = doc
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
protected
|
50
|
-
def find_target
|
51
|
-
target_class.first(association.query_options.merge(foreign_key => owner.id))
|
52
|
-
end
|
53
|
-
|
54
|
-
def instantiate_target(instantiator, attrs={})
|
55
|
-
@target = target_class.send(instantiator, attrs.update(foreign_key => owner.id))
|
56
|
-
loaded
|
57
|
-
@target
|
58
|
-
end
|
59
|
-
|
60
|
-
def target_class
|
61
|
-
@target_class ||= options[:class] || (options[:class_name] || association.name.to_s.camelize).constantize
|
62
|
-
end
|
63
|
-
|
64
|
-
def foreign_key
|
65
|
-
options[:foreign_key] || owner.class.name.foreign_key
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
module MongoMapper
|
3
|
+
module Plugins
|
4
|
+
module Associations
|
5
|
+
class OneProxy < Proxy
|
6
|
+
undef_method :object_id
|
7
|
+
|
8
|
+
def build(attrs={})
|
9
|
+
instantiate_target(:new, attrs)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create(attrs={})
|
13
|
+
instantiate_target(:create, attrs)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create!(attrs={})
|
17
|
+
instantiate_target(:create!, attrs)
|
18
|
+
end
|
19
|
+
|
20
|
+
def replace(doc)
|
21
|
+
load_target
|
22
|
+
|
23
|
+
if !target.nil? && target != doc
|
24
|
+
if options[:dependent] && !target.new?
|
25
|
+
case options[:dependent]
|
26
|
+
when :delete
|
27
|
+
target.delete
|
28
|
+
when :destroy
|
29
|
+
target.destroy
|
30
|
+
when :nullify
|
31
|
+
target[foreign_key] = nil
|
32
|
+
target.save
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
reset
|
38
|
+
|
39
|
+
unless doc.nil?
|
40
|
+
owner.save if owner.new?
|
41
|
+
doc = klass.new(doc) unless klass === doc
|
42
|
+
doc[foreign_key] = owner.id
|
43
|
+
doc.save if doc.new?
|
44
|
+
loaded
|
45
|
+
@target = doc
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
def find_target
|
51
|
+
target_class.first(association.query_options.merge(foreign_key => owner.id))
|
52
|
+
end
|
53
|
+
|
54
|
+
def instantiate_target(instantiator, attrs={})
|
55
|
+
@target = target_class.send(instantiator, attrs.update(foreign_key => owner.id))
|
56
|
+
loaded
|
57
|
+
@target
|
58
|
+
end
|
59
|
+
|
60
|
+
def target_class
|
61
|
+
@target_class ||= options[:class] || (options[:class_name] || association.name.to_s.camelize).constantize
|
62
|
+
end
|
63
|
+
|
64
|
+
def foreign_key
|
65
|
+
options[:foreign_key] || owner.class.name.foreign_key
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -1,125 +1,125 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
module MongoMapper
|
3
|
-
module Plugins
|
4
|
-
module Associations
|
5
|
-
class Proxy
|
6
|
-
alias :proxy_respond_to? :respond_to?
|
7
|
-
alias :proxy_extend :extend
|
8
|
-
|
9
|
-
instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$|proxy_|^object_id$)/ }
|
10
|
-
|
11
|
-
attr_reader :owner, :association, :target
|
12
|
-
|
13
|
-
alias :proxy_owner :owner
|
14
|
-
alias :proxy_target :target
|
15
|
-
alias :proxy_association :association
|
16
|
-
|
17
|
-
delegate :klass, :to => :proxy_association
|
18
|
-
delegate :options, :to => :proxy_association
|
19
|
-
delegate :collection, :to => :klass
|
20
|
-
|
21
|
-
def initialize(owner, association)
|
22
|
-
@owner, @association, @loaded = owner, association, false
|
23
|
-
Array(association.options[:extend]).each { |ext| proxy_extend(ext) }
|
24
|
-
reset
|
25
|
-
end
|
26
|
-
|
27
|
-
def inspect
|
28
|
-
load_target
|
29
|
-
target.inspect
|
30
|
-
end
|
31
|
-
|
32
|
-
def loaded?
|
33
|
-
@loaded
|
34
|
-
end
|
35
|
-
|
36
|
-
def loaded
|
37
|
-
@loaded = true
|
38
|
-
end
|
39
|
-
|
40
|
-
def nil?
|
41
|
-
load_target
|
42
|
-
target.nil?
|
43
|
-
end
|
44
|
-
|
45
|
-
def blank?
|
46
|
-
load_target
|
47
|
-
target.blank?
|
48
|
-
end
|
49
|
-
|
50
|
-
def present?
|
51
|
-
load_target
|
52
|
-
target.present?
|
53
|
-
end
|
54
|
-
|
55
|
-
def reload
|
56
|
-
reset
|
57
|
-
load_target
|
58
|
-
self unless target.nil?
|
59
|
-
end
|
60
|
-
|
61
|
-
def replace(v)
|
62
|
-
raise NotImplementedError
|
63
|
-
end
|
64
|
-
|
65
|
-
def reset
|
66
|
-
@loaded = false
|
67
|
-
@target = nil
|
68
|
-
end
|
69
|
-
|
70
|
-
def respond_to?(*args)
|
71
|
-
proxy_respond_to?(*args) || (load_target && target.respond_to?(*args))
|
72
|
-
end
|
73
|
-
|
74
|
-
def send(method, *args)
|
75
|
-
if proxy_respond_to?(method)
|
76
|
-
super
|
77
|
-
else
|
78
|
-
load_target
|
79
|
-
target.send(method, *args)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def ===(other)
|
84
|
-
load_target
|
85
|
-
other === target
|
86
|
-
end
|
87
|
-
|
88
|
-
protected
|
89
|
-
def method_missing(method, *args, &block)
|
90
|
-
if load_target
|
91
|
-
if block_given?
|
92
|
-
target.send(method, *args) { |*block_args| block.call(*block_args) }
|
93
|
-
else
|
94
|
-
target.send(method, *args)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def load_target
|
100
|
-
unless loaded?
|
101
|
-
if @target.is_a?(Array) && @target.any?
|
102
|
-
@target = find_target + @target.find_all { |record| record.new? }
|
103
|
-
else
|
104
|
-
@target = find_target
|
105
|
-
end
|
106
|
-
loaded
|
107
|
-
end
|
108
|
-
@target
|
109
|
-
rescue MongoMapper::DocumentNotFound
|
110
|
-
reset
|
111
|
-
end
|
112
|
-
|
113
|
-
def find_target
|
114
|
-
raise NotImplementedError
|
115
|
-
end
|
116
|
-
|
117
|
-
def flatten_deeper(array)
|
118
|
-
array.collect do |element|
|
119
|
-
(element.respond_to?(:flatten) && !element.is_a?(Hash)) ? element.flatten : element
|
120
|
-
end.flatten
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
module MongoMapper
|
3
|
+
module Plugins
|
4
|
+
module Associations
|
5
|
+
class Proxy
|
6
|
+
alias :proxy_respond_to? :respond_to?
|
7
|
+
alias :proxy_extend :extend
|
8
|
+
|
9
|
+
instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$|proxy_|^object_id$)/ }
|
10
|
+
|
11
|
+
attr_reader :owner, :association, :target
|
12
|
+
|
13
|
+
alias :proxy_owner :owner
|
14
|
+
alias :proxy_target :target
|
15
|
+
alias :proxy_association :association
|
16
|
+
|
17
|
+
delegate :klass, :to => :proxy_association
|
18
|
+
delegate :options, :to => :proxy_association
|
19
|
+
delegate :collection, :to => :klass
|
20
|
+
|
21
|
+
def initialize(owner, association)
|
22
|
+
@owner, @association, @loaded = owner, association, false
|
23
|
+
Array(association.options[:extend]).each { |ext| proxy_extend(ext) }
|
24
|
+
reset
|
25
|
+
end
|
26
|
+
|
27
|
+
def inspect
|
28
|
+
load_target
|
29
|
+
target.inspect
|
30
|
+
end
|
31
|
+
|
32
|
+
def loaded?
|
33
|
+
@loaded
|
34
|
+
end
|
35
|
+
|
36
|
+
def loaded
|
37
|
+
@loaded = true
|
38
|
+
end
|
39
|
+
|
40
|
+
def nil?
|
41
|
+
load_target
|
42
|
+
target.nil?
|
43
|
+
end
|
44
|
+
|
45
|
+
def blank?
|
46
|
+
load_target
|
47
|
+
target.blank?
|
48
|
+
end
|
49
|
+
|
50
|
+
def present?
|
51
|
+
load_target
|
52
|
+
target.present?
|
53
|
+
end
|
54
|
+
|
55
|
+
def reload
|
56
|
+
reset
|
57
|
+
load_target
|
58
|
+
self unless target.nil?
|
59
|
+
end
|
60
|
+
|
61
|
+
def replace(v)
|
62
|
+
raise NotImplementedError
|
63
|
+
end
|
64
|
+
|
65
|
+
def reset
|
66
|
+
@loaded = false
|
67
|
+
@target = nil
|
68
|
+
end
|
69
|
+
|
70
|
+
def respond_to?(*args)
|
71
|
+
proxy_respond_to?(*args) || (load_target && target.respond_to?(*args))
|
72
|
+
end
|
73
|
+
|
74
|
+
def send(method, *args)
|
75
|
+
if proxy_respond_to?(method)
|
76
|
+
super
|
77
|
+
else
|
78
|
+
load_target
|
79
|
+
target.send(method, *args)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def ===(other)
|
84
|
+
load_target
|
85
|
+
other === target
|
86
|
+
end
|
87
|
+
|
88
|
+
protected
|
89
|
+
def method_missing(method, *args, &block)
|
90
|
+
if load_target
|
91
|
+
if block_given?
|
92
|
+
target.send(method, *args) { |*block_args| block.call(*block_args) }
|
93
|
+
else
|
94
|
+
target.send(method, *args)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def load_target
|
100
|
+
unless loaded?
|
101
|
+
if @target.is_a?(Array) && @target.any?
|
102
|
+
@target = find_target + @target.find_all { |record| record.new? }
|
103
|
+
else
|
104
|
+
@target = find_target
|
105
|
+
end
|
106
|
+
loaded
|
107
|
+
end
|
108
|
+
@target
|
109
|
+
rescue MongoMapper::DocumentNotFound
|
110
|
+
reset
|
111
|
+
end
|
112
|
+
|
113
|
+
def find_target
|
114
|
+
raise NotImplementedError
|
115
|
+
end
|
116
|
+
|
117
|
+
def flatten_deeper(array)
|
118
|
+
array.collect do |element|
|
119
|
+
(element.respond_to?(:flatten) && !element.is_a?(Hash)) ? element.flatten : element
|
120
|
+
end.flatten
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|