pwnash-mongo_mapper 0.7.5 → 0.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/mongo_mapper.rb +6 -8
- data/lib/mongo_mapper/document.rb +6 -281
- data/lib/mongo_mapper/embedded_document.rb +5 -45
- data/lib/mongo_mapper/extensions.rb +190 -0
- data/lib/mongo_mapper/plugins.rb +27 -18
- data/lib/mongo_mapper/plugins/associations.rb +7 -6
- data/lib/mongo_mapper/plugins/associations/base.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/collection.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +2 -1
- data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +4 -4
- data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/one_proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/callbacks.rb +4 -3
- data/lib/mongo_mapper/plugins/clone.rb +1 -0
- data/lib/mongo_mapper/plugins/descendants.rb +1 -0
- data/lib/mongo_mapper/plugins/dirty.rb +1 -0
- data/lib/mongo_mapper/plugins/document.rb +40 -0
- data/lib/mongo_mapper/plugins/dynamic_querying.rb +42 -0
- data/lib/mongo_mapper/{support/find.rb → plugins/dynamic_querying/dynamic_finder.rb} +2 -36
- data/lib/mongo_mapper/plugins/embedded_document.rb +48 -0
- data/lib/mongo_mapper/plugins/equality.rb +1 -0
- data/lib/mongo_mapper/plugins/identity_map.rb +8 -11
- data/lib/mongo_mapper/plugins/indexes.rb +11 -0
- data/lib/mongo_mapper/plugins/inspect.rb +1 -0
- data/lib/mongo_mapper/plugins/keys.rb +7 -9
- data/lib/mongo_mapper/plugins/keys/key.rb +12 -2
- data/lib/mongo_mapper/plugins/logger.rb +1 -0
- data/lib/mongo_mapper/plugins/modifiers.rb +3 -2
- data/lib/mongo_mapper/plugins/pagination.rb +1 -0
- data/lib/mongo_mapper/plugins/pagination/proxy.rb +1 -0
- data/lib/mongo_mapper/plugins/persistence.rb +1 -0
- data/lib/mongo_mapper/plugins/protected.rb +1 -0
- data/lib/mongo_mapper/plugins/query_logger.rb +5 -10
- data/lib/mongo_mapper/plugins/querying.rb +236 -0
- data/lib/mongo_mapper/plugins/rails.rb +1 -0
- data/lib/mongo_mapper/plugins/sci.rb +31 -0
- data/lib/mongo_mapper/plugins/serialization.rb +1 -0
- data/lib/mongo_mapper/plugins/timestamps.rb +1 -0
- data/lib/mongo_mapper/plugins/userstamps.rb +1 -0
- data/lib/mongo_mapper/plugins/validations.rb +5 -1
- data/lib/mongo_mapper/query.rb +53 -120
- data/lib/mongo_mapper/support.rb +2 -213
- data/lib/mongo_mapper/support/descendant_appends.rb +3 -6
- data/lib/mongo_mapper/version.rb +2 -1
- metadata +156 -190
- data/.gitignore +0 -10
- data/Rakefile +0 -37
- data/mongo_mapper.gemspec +0 -216
- data/performance/read_write.rb +0 -52
- data/specs.watchr +0 -51
- data/test/NOTE_ON_TESTING +0 -1
- data/test/active_model_lint_test.rb +0 -13
- data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +0 -63
- data/test/functional/associations/test_belongs_to_proxy.rb +0 -101
- data/test/functional/associations/test_in_array_proxy.rb +0 -325
- data/test/functional/associations/test_many_documents_as_proxy.rb +0 -229
- data/test/functional/associations/test_many_documents_proxy.rb +0 -536
- data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +0 -176
- data/test/functional/associations/test_many_embedded_proxy.rb +0 -256
- data/test/functional/associations/test_many_polymorphic_proxy.rb +0 -302
- data/test/functional/associations/test_one_embedded_proxy.rb +0 -68
- data/test/functional/associations/test_one_proxy.rb +0 -196
- data/test/functional/test_associations.rb +0 -44
- data/test/functional/test_binary.rb +0 -27
- data/test/functional/test_callbacks.rb +0 -151
- data/test/functional/test_dirty.rb +0 -163
- data/test/functional/test_document.rb +0 -1219
- data/test/functional/test_embedded_document.rb +0 -210
- data/test/functional/test_identity_map.rb +0 -507
- data/test/functional/test_indexing.rb +0 -44
- data/test/functional/test_logger.rb +0 -20
- data/test/functional/test_modifiers.rb +0 -416
- data/test/functional/test_pagination.rb +0 -93
- data/test/functional/test_protected.rb +0 -163
- data/test/functional/test_string_id_compatibility.rb +0 -67
- data/test/functional/test_timestamps.rb +0 -64
- data/test/functional/test_userstamps.rb +0 -28
- data/test/functional/test_validations.rb +0 -342
- data/test/models.rb +0 -227
- data/test/support/custom_matchers.rb +0 -37
- data/test/support/timing.rb +0 -16
- data/test/test_helper.rb +0 -64
- data/test/unit/associations/test_base.rb +0 -212
- data/test/unit/associations/test_proxy.rb +0 -105
- data/test/unit/serializers/test_json_serializer.rb +0 -202
- data/test/unit/test_descendant_appends.rb +0 -71
- data/test/unit/test_document.rb +0 -225
- data/test/unit/test_dynamic_finder.rb +0 -123
- data/test/unit/test_embedded_document.rb +0 -657
- data/test/unit/test_keys.rb +0 -216
- data/test/unit/test_mongo_mapper.rb +0 -118
- data/test/unit/test_pagination.rb +0 -160
- data/test/unit/test_plugins.rb +0 -50
- data/test/unit/test_query.rb +0 -374
- data/test/unit/test_rails.rb +0 -181
- data/test/unit/test_rails_compatibility.rb +0 -52
- data/test/unit/test_serialization.rb +0 -51
- data/test/unit/test_support.rb +0 -390
- data/test/unit/test_time_zones.rb +0 -39
- data/test/unit/test_validations.rb +0 -544
data/lib/mongo_mapper/plugins.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
module MongoMapper
|
2
3
|
module Plugins
|
3
4
|
def plugins
|
@@ -11,24 +12,32 @@ module MongoMapper
|
|
11
12
|
plugins << mod
|
12
13
|
end
|
13
14
|
|
14
|
-
autoload :
|
15
|
-
autoload :
|
16
|
-
|
17
|
-
autoload :
|
18
|
-
autoload :
|
19
|
-
autoload :
|
20
|
-
autoload :
|
21
|
-
autoload :
|
22
|
-
autoload :
|
23
|
-
autoload :
|
24
|
-
autoload :
|
25
|
-
autoload :
|
26
|
-
autoload :
|
27
|
-
autoload :
|
28
|
-
autoload :
|
29
|
-
autoload :
|
30
|
-
autoload :
|
31
|
-
autoload :
|
15
|
+
autoload :Document, 'mongo_mapper/plugins/document'
|
16
|
+
autoload :EmbeddedDocument, 'mongo_mapper/plugins/embedded_document'
|
17
|
+
|
18
|
+
autoload :Callbacks, 'mongo_mapper/plugins/callbacks'
|
19
|
+
autoload :Clone, 'mongo_mapper/plugins/clone'
|
20
|
+
autoload :Descendants, 'mongo_mapper/plugins/descendants'
|
21
|
+
autoload :Dirty, 'mongo_mapper/plugins/dirty'
|
22
|
+
autoload :DynamicQuerying, 'mongo_mapper/plugins/dynamic_querying'
|
23
|
+
autoload :Equality, 'mongo_mapper/plugins/equality'
|
24
|
+
autoload :IdentityMap, 'mongo_mapper/plugins/identity_map'
|
25
|
+
autoload :Inspect, 'mongo_mapper/plugins/inspect'
|
26
|
+
autoload :Indexes, 'mongo_mapper/plugins/indexes'
|
27
|
+
autoload :Keys, 'mongo_mapper/plugins/keys'
|
28
|
+
autoload :Logger, 'mongo_mapper/plugins/logger'
|
29
|
+
autoload :Modifiers, 'mongo_mapper/plugins/modifiers'
|
30
|
+
autoload :Persistence, 'mongo_mapper/plugins/persistence'
|
31
|
+
autoload :Protected, 'mongo_mapper/plugins/protected'
|
32
|
+
autoload :Querying, 'mongo_mapper/plugins/querying'
|
33
|
+
autoload :Rails, 'mongo_mapper/plugins/rails'
|
34
|
+
autoload :Sci, 'mongo_mapper/plugins/sci'
|
35
|
+
autoload :Serialization, 'mongo_mapper/plugins/serialization'
|
36
|
+
autoload :Timestamps, 'mongo_mapper/plugins/timestamps'
|
37
|
+
autoload :Userstamps, 'mongo_mapper/plugins/userstamps'
|
38
|
+
autoload :Validations, 'mongo_mapper/plugins/validations'
|
39
|
+
autoload :QueryLogger, 'mongo_mapper/plugins/query_logger'
|
40
|
+
|
32
41
|
end
|
33
42
|
end
|
34
43
|
|
@@ -1,7 +1,13 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
module MongoMapper
|
2
3
|
module Plugins
|
3
4
|
module Associations
|
4
5
|
module ClassMethods
|
6
|
+
def inherited(subclass)
|
7
|
+
subclass.associations = associations.dup
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
5
11
|
def belongs_to(association_id, options={}, &extension)
|
6
12
|
create_association(:belongs_to, association_id, options, &extension)
|
7
13
|
end
|
@@ -22,11 +28,6 @@ module MongoMapper
|
|
22
28
|
@associations = hash
|
23
29
|
end
|
24
30
|
|
25
|
-
def inherited(subclass)
|
26
|
-
subclass.associations = associations.dup
|
27
|
-
super
|
28
|
-
end
|
29
|
-
|
30
31
|
private
|
31
32
|
def create_association(type, name, options, &extension)
|
32
33
|
association = Associations::Base.new(type, name, options, &extension)
|
@@ -85,7 +86,7 @@ module MongoMapper
|
|
85
86
|
proxy
|
86
87
|
end
|
87
88
|
|
88
|
-
def save_to_collection(options
|
89
|
+
def save_to_collection(options={})
|
89
90
|
super
|
90
91
|
associations.each do |association_name, association|
|
91
92
|
proxy = get_proxy(association)
|
@@ -1,8 +1,9 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
module MongoMapper
|
2
3
|
module Plugins
|
3
4
|
module Associations
|
4
5
|
class ManyDocumentsProxy < Collection
|
5
|
-
include
|
6
|
+
include MongoMapper::Plugins::DynamicQuerying::ClassMethods
|
6
7
|
|
7
8
|
def find(*args)
|
8
9
|
options = args.extract_options!
|
@@ -82,14 +83,13 @@ module MongoMapper
|
|
82
83
|
end
|
83
84
|
|
84
85
|
def nullify
|
85
|
-
|
86
|
-
all(criteria).each do |doc|
|
86
|
+
all.each do |doc|
|
87
87
|
doc.update_attributes(self.foreign_key => nil)
|
88
88
|
end
|
89
89
|
reset
|
90
90
|
end
|
91
91
|
|
92
|
-
def save_to_collection(options
|
92
|
+
def save_to_collection(options={})
|
93
93
|
@target.each { |doc| doc.save(options) } if @target
|
94
94
|
end
|
95
95
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
# Almost all of this callback stuff is pulled directly from ActiveSupport
|
2
3
|
# in the interest of support rails 2 and 3 at the same time and is the
|
3
4
|
# same copyright as rails.
|
@@ -76,7 +77,7 @@ module MongoMapper
|
|
76
77
|
result
|
77
78
|
end
|
78
79
|
|
79
|
-
def run_callbacks(kind, options
|
80
|
+
def run_callbacks(kind, options={}, &block)
|
80
81
|
callback_chain_method = "#{kind}_callback_chain"
|
81
82
|
return unless self.class.respond_to?(callback_chain_method)
|
82
83
|
self.class.send(callback_chain_method).run(self, options, &block)
|
@@ -122,7 +123,7 @@ module MongoMapper
|
|
122
123
|
new(methods)
|
123
124
|
end
|
124
125
|
|
125
|
-
def run(object, options
|
126
|
+
def run(object, options={}, &terminator)
|
126
127
|
enumerator = options[:enumerator] || :each
|
127
128
|
|
128
129
|
unless block_given?
|
@@ -169,7 +170,7 @@ module MongoMapper
|
|
169
170
|
class Callback
|
170
171
|
attr_reader :kind, :method, :identifier, :options
|
171
172
|
|
172
|
-
def initialize(kind, method, options
|
173
|
+
def initialize(kind, method, options={})
|
173
174
|
@kind = kind
|
174
175
|
@method = method
|
175
176
|
@identifier = options[:identifier]
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module MongoMapper
|
2
|
+
module Plugins
|
3
|
+
module Document
|
4
|
+
module ClassMethods
|
5
|
+
def embeddable?
|
6
|
+
false
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module InstanceMethods
|
11
|
+
def new?
|
12
|
+
@new
|
13
|
+
end
|
14
|
+
|
15
|
+
def destroyed?
|
16
|
+
@_destroyed == true
|
17
|
+
end
|
18
|
+
|
19
|
+
def reload
|
20
|
+
if doc = self.class.query(:_id => id).query.first
|
21
|
+
tap do |instance|
|
22
|
+
instance.class.associations.each_key do |association_name|
|
23
|
+
send(association_name).reset if respond_to?(association_name)
|
24
|
+
end
|
25
|
+
instance.attributes = doc
|
26
|
+
end
|
27
|
+
else
|
28
|
+
raise DocumentNotFound, "Document match #{_id.inspect} does not exist in #{collection.name} collection"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Used by embedded docs to find root easily without if/respond_to? stuff.
|
33
|
+
# Documents are always root documents.
|
34
|
+
def _root_document
|
35
|
+
self
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module MongoMapper
|
2
|
+
module Plugins
|
3
|
+
module DynamicQuerying
|
4
|
+
autoload :DynamicFinder, 'mongo_mapper/plugins/dynamic_querying/dynamic_finder'
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def dynamic_find(finder, args)
|
8
|
+
attributes = {}
|
9
|
+
|
10
|
+
finder.attributes.each_with_index do |attr, index|
|
11
|
+
attributes[attr] = args[index]
|
12
|
+
end
|
13
|
+
|
14
|
+
options = args.extract_options!.merge(attributes)
|
15
|
+
|
16
|
+
if result = send(finder.finder, options)
|
17
|
+
result
|
18
|
+
else
|
19
|
+
if finder.raise?
|
20
|
+
raise DocumentNotFound, "Couldn't find Document with #{attributes.inspect} in collection named #{collection.name}"
|
21
|
+
end
|
22
|
+
|
23
|
+
if finder.instantiator
|
24
|
+
self.send(finder.instantiator, attributes)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
def method_missing(method, *args, &block)
|
31
|
+
finder = DynamicFinder.new(method)
|
32
|
+
|
33
|
+
if finder.found?
|
34
|
+
dynamic_find(finder, args)
|
35
|
+
else
|
36
|
+
super
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,29 +1,6 @@
|
|
1
1
|
module MongoMapper
|
2
|
-
module
|
3
|
-
|
4
|
-
module Find
|
5
|
-
def dynamic_find(finder, args)
|
6
|
-
attributes = {}
|
7
|
-
|
8
|
-
finder.attributes.each_with_index do |attr, index|
|
9
|
-
attributes[attr] = args[index]
|
10
|
-
end
|
11
|
-
|
12
|
-
options = args.extract_options!.merge(attributes)
|
13
|
-
|
14
|
-
if result = send(finder.finder, options)
|
15
|
-
result
|
16
|
-
else
|
17
|
-
if finder.raise?
|
18
|
-
raise DocumentNotFound, "Couldn't find Document with #{attributes.inspect} in collection named #{collection.name}"
|
19
|
-
end
|
20
|
-
|
21
|
-
if finder.instantiator
|
22
|
-
self.send(finder.instantiator, attributes)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
2
|
+
module Plugins
|
3
|
+
module DynamicQuerying
|
27
4
|
class DynamicFinder
|
28
5
|
attr_reader :method, :attributes, :finder, :bang, :instantiator
|
29
6
|
|
@@ -61,17 +38,6 @@ module MongoMapper
|
|
61
38
|
@attributes = names && names.split('_and_')
|
62
39
|
end
|
63
40
|
end
|
64
|
-
|
65
|
-
protected
|
66
|
-
def method_missing(method, *args, &block)
|
67
|
-
finder = DynamicFinder.new(method)
|
68
|
-
|
69
|
-
if finder.found?
|
70
|
-
dynamic_find(finder, args)
|
71
|
-
else
|
72
|
-
super
|
73
|
-
end
|
74
|
-
end
|
75
41
|
end
|
76
42
|
end
|
77
43
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module MongoMapper
|
2
|
+
module Plugins
|
3
|
+
module EmbeddedDocument
|
4
|
+
def self.configure(model)
|
5
|
+
model.class_eval do
|
6
|
+
attr_reader :_root_document, :_parent_document
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def embeddable?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def embedded_in(owner_name)
|
16
|
+
define_method(owner_name) { _parent_document }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module InstanceMethods
|
21
|
+
def new?
|
22
|
+
_root_document.try(:new?) || @new
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroyed?
|
26
|
+
!!_root_document.try(:destroyed?)
|
27
|
+
end
|
28
|
+
|
29
|
+
def save(options={})
|
30
|
+
_root_document.try(:save, options).tap do |result|
|
31
|
+
@new = false if result
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def save!(options={})
|
36
|
+
_root_document.try(:save, options).tap do |result|
|
37
|
+
@new = false if result
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def _parent_document=(value)
|
42
|
+
@_root_document = value._root_document
|
43
|
+
@_parent_document = value
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
module MongoMapper
|
2
3
|
module Plugins
|
3
4
|
module IdentityMap
|
@@ -28,25 +29,25 @@ module MongoMapper
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def find_one(options={})
|
31
|
-
|
32
|
-
|
33
|
-
if
|
34
|
-
identity_map[
|
32
|
+
query = query(options)
|
33
|
+
|
34
|
+
if query.simple? && identity_map.key?(query[:_id])
|
35
|
+
identity_map[query[:_id]]
|
35
36
|
else
|
36
37
|
super.tap do |document|
|
37
|
-
remove_documents_from_map(document) if
|
38
|
+
remove_documents_from_map(document) if query.fields?
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
43
|
def find_many(options)
|
43
|
-
criteria, query_options = to_query(options)
|
44
44
|
super.tap do |documents|
|
45
|
-
remove_documents_from_map(documents) if
|
45
|
+
remove_documents_from_map(documents) if query(options).fields?
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
def load(attrs)
|
50
|
+
return nil if attrs.nil?
|
50
51
|
document = identity_map[attrs['_id']]
|
51
52
|
|
52
53
|
if document.nil? || identity_map_off?
|
@@ -91,10 +92,6 @@ module MongoMapper
|
|
91
92
|
end
|
92
93
|
end
|
93
94
|
|
94
|
-
def simple_find?(criteria)
|
95
|
-
criteria.keys == [:_id] || criteria.keys.to_set == [:_id, :_type].to_set
|
96
|
-
end
|
97
|
-
|
98
95
|
def selecting_fields?(options)
|
99
96
|
!options[:fields].nil?
|
100
97
|
end
|