mongo_mapper 0.6.10 → 0.7.0
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/README.rdoc +5 -14
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/mongo_mapper.rb +48 -56
- data/lib/mongo_mapper/document.rb +136 -164
- data/lib/mongo_mapper/embedded_document.rb +29 -354
- data/lib/mongo_mapper/plugins.rb +31 -0
- data/lib/mongo_mapper/plugins/associations.rb +105 -0
- data/lib/mongo_mapper/plugins/associations/base.rb +123 -0
- data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +30 -0
- data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +25 -0
- data/lib/mongo_mapper/plugins/associations/collection.rb +21 -0
- data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +50 -0
- data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +139 -0
- data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +28 -0
- data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +117 -0
- data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +31 -0
- data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +23 -0
- data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +13 -0
- data/lib/mongo_mapper/plugins/associations/one_proxy.rb +68 -0
- data/lib/mongo_mapper/plugins/associations/proxy.rb +118 -0
- data/lib/mongo_mapper/plugins/callbacks.rb +65 -0
- data/lib/mongo_mapper/plugins/clone.rb +13 -0
- data/lib/mongo_mapper/plugins/descendants.rb +16 -0
- data/lib/mongo_mapper/plugins/dirty.rb +119 -0
- data/lib/mongo_mapper/plugins/equality.rb +23 -0
- data/lib/mongo_mapper/plugins/identity_map.rb +122 -0
- data/lib/mongo_mapper/plugins/inspect.rb +14 -0
- data/lib/mongo_mapper/plugins/keys.rb +324 -0
- data/lib/mongo_mapper/plugins/logger.rb +17 -0
- data/lib/mongo_mapper/plugins/pagination.rb +24 -0
- data/lib/mongo_mapper/plugins/pagination/proxy.rb +68 -0
- data/lib/mongo_mapper/plugins/protected.rb +45 -0
- data/lib/mongo_mapper/plugins/rails.rb +45 -0
- data/lib/mongo_mapper/plugins/serialization.rb +105 -0
- data/lib/mongo_mapper/plugins/validations.rb +46 -0
- data/lib/mongo_mapper/query.rb +130 -0
- data/lib/mongo_mapper/support.rb +40 -17
- data/lib/mongo_mapper/support/descendant_appends.rb +46 -0
- data/lib/mongo_mapper/support/find.rb +77 -0
- data/mongo_mapper.gemspec +55 -38
- data/performance/read_write.rb +52 -0
- data/specs.watchr +23 -2
- data/test/functional/associations/test_belongs_to_proxy.rb +12 -10
- data/test/functional/associations/test_many_documents_as_proxy.rb +4 -21
- data/test/functional/associations/test_many_documents_proxy.rb +2 -8
- data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +59 -39
- data/test/functional/associations/test_many_embedded_proxy.rb +145 -81
- data/test/functional/associations/test_many_polymorphic_proxy.rb +2 -40
- data/test/functional/associations/test_one_proxy.rb +25 -10
- data/test/functional/test_binary.rb +2 -8
- data/test/functional/test_callbacks.rb +1 -5
- data/test/functional/test_dirty.rb +27 -23
- data/test/functional/test_document.rb +224 -165
- data/test/functional/test_embedded_document.rb +72 -82
- data/test/functional/test_identity_map.rb +508 -0
- data/test/functional/test_modifiers.rb +15 -5
- data/test/functional/test_pagination.rb +1 -3
- data/test/functional/test_protected.rb +155 -0
- data/test/functional/test_string_id_compatibility.rb +7 -12
- data/test/functional/test_validations.rb +26 -58
- data/test/models.rb +0 -39
- data/test/test_helper.rb +37 -3
- data/test/unit/associations/test_base.rb +5 -5
- data/test/unit/associations/test_proxy.rb +8 -6
- data/test/unit/test_descendant_appends.rb +71 -0
- data/test/unit/test_document.rb +71 -76
- data/test/unit/test_dynamic_finder.rb +27 -29
- data/test/unit/test_embedded_document.rb +555 -601
- data/test/unit/{test_key.rb → test_keys.rb} +2 -5
- data/test/unit/test_mongo_mapper.rb +69 -9
- data/test/unit/test_pagination.rb +40 -32
- data/test/unit/test_plugins.rb +50 -0
- data/test/unit/{test_finder_options.rb → test_query.rb} +74 -65
- data/test/unit/test_rails.rb +123 -0
- data/test/unit/{test_serializations.rb → test_serialization.rb} +1 -2
- data/test/unit/test_support.rb +23 -7
- data/test/unit/test_time_zones.rb +3 -4
- data/test/unit/test_validations.rb +58 -17
- metadata +53 -36
- data/lib/mongo_mapper/associations.rb +0 -78
- data/lib/mongo_mapper/associations/base.rb +0 -119
- data/lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb +0 -26
- data/lib/mongo_mapper/associations/belongs_to_proxy.rb +0 -21
- data/lib/mongo_mapper/associations/collection.rb +0 -19
- data/lib/mongo_mapper/associations/in_array_proxy.rb +0 -137
- data/lib/mongo_mapper/associations/many_documents_as_proxy.rb +0 -26
- data/lib/mongo_mapper/associations/many_documents_proxy.rb +0 -115
- data/lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb +0 -31
- data/lib/mongo_mapper/associations/many_embedded_proxy.rb +0 -54
- data/lib/mongo_mapper/associations/many_polymorphic_proxy.rb +0 -11
- data/lib/mongo_mapper/associations/one_proxy.rb +0 -64
- data/lib/mongo_mapper/associations/proxy.rb +0 -116
- data/lib/mongo_mapper/callbacks.rb +0 -61
- data/lib/mongo_mapper/dirty.rb +0 -117
- data/lib/mongo_mapper/dynamic_finder.rb +0 -74
- data/lib/mongo_mapper/finder_options.rb +0 -145
- data/lib/mongo_mapper/key.rb +0 -36
- data/lib/mongo_mapper/mongo_mapper.rb +0 -125
- data/lib/mongo_mapper/pagination.rb +0 -66
- data/lib/mongo_mapper/rails_compatibility/document.rb +0 -15
- data/lib/mongo_mapper/rails_compatibility/embedded_document.rb +0 -28
- data/lib/mongo_mapper/serialization.rb +0 -54
- data/lib/mongo_mapper/serializers/json_serializer.rb +0 -48
- data/lib/mongo_mapper/validations.rb +0 -39
- data/test/functional/test_rails_compatibility.rb +0 -25
data/lib/mongo_mapper/support.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'set'
|
2
|
-
|
3
1
|
class Array
|
4
2
|
def self.to_mongo(value)
|
5
3
|
value = value.respond_to?(:lines) ? value.lines : value
|
@@ -26,11 +24,18 @@ class Binary
|
|
26
24
|
end
|
27
25
|
|
28
26
|
class Boolean
|
27
|
+
BOOLEAN_MAPPING = {
|
28
|
+
true => true, 'true' => true, 'TRUE' => true, 'True' => true, 't' => true, 'T' => true, '1' => true, 1 => true, 1.0 => true,
|
29
|
+
false => false, 'false' => false, 'FALSE' => false, 'False' => false, 'f' => false, 'F' => false, '0' => false, 0 => false, 0.0 => false, nil => false
|
30
|
+
}
|
31
|
+
|
29
32
|
def self.to_mongo(value)
|
30
33
|
if value.is_a?(Boolean)
|
31
34
|
value
|
32
35
|
else
|
33
|
-
|
36
|
+
v = BOOLEAN_MAPPING[value]
|
37
|
+
v = value.to_s.downcase == 'true' if v.nil? # Check all mixed case spellings for true
|
38
|
+
v
|
34
39
|
end
|
35
40
|
end
|
36
41
|
|
@@ -41,8 +46,12 @@ end
|
|
41
46
|
|
42
47
|
class Date
|
43
48
|
def self.to_mongo(value)
|
44
|
-
|
45
|
-
|
49
|
+
if value.nil? || value == ''
|
50
|
+
nil
|
51
|
+
else
|
52
|
+
date = value.is_a?(Date) || value.is_a?(Time) ? value : Date.parse(value.to_s)
|
53
|
+
Time.utc(date.year, date.month, date.day)
|
54
|
+
end
|
46
55
|
rescue
|
47
56
|
nil
|
48
57
|
end
|
@@ -71,7 +80,7 @@ end
|
|
71
80
|
class Integer
|
72
81
|
def self.to_mongo(value)
|
73
82
|
value_to_i = value.to_i
|
74
|
-
if value_to_i == 0
|
83
|
+
if value_to_i == 0 && value != value_to_i
|
75
84
|
value.to_s =~ /^(0x|0b)?0+/ ? 0 : nil
|
76
85
|
else
|
77
86
|
value_to_i
|
@@ -154,15 +163,20 @@ class String
|
|
154
163
|
end
|
155
164
|
end
|
156
165
|
|
166
|
+
class SymbolOperator
|
167
|
+
attr_reader :field, :operator
|
168
|
+
|
169
|
+
def initialize(field, operator, options={})
|
170
|
+
@field, @operator = field, operator
|
171
|
+
end unless method_defined?(:initialize)
|
172
|
+
end
|
173
|
+
|
157
174
|
class Symbol
|
158
|
-
%w
|
159
|
-
define_method
|
160
|
-
|
161
|
-
end
|
175
|
+
%w(gt lt gte lte ne in nin mod all size where exists asc desc).each do |operator|
|
176
|
+
define_method(operator) do
|
177
|
+
SymbolOperator.new(self, operator)
|
178
|
+
end unless method_defined?(operator)
|
162
179
|
end
|
163
|
-
|
164
|
-
def asc; MongoMapper::OrderOperator.new(self, 'asc') end
|
165
|
-
def desc; MongoMapper::OrderOperator.new(self, 'desc') end
|
166
180
|
end
|
167
181
|
|
168
182
|
class Time
|
@@ -170,8 +184,9 @@ class Time
|
|
170
184
|
if value.nil? || value == ''
|
171
185
|
nil
|
172
186
|
else
|
173
|
-
time = MongoMapper.time_class.parse(value.to_s)
|
174
|
-
time
|
187
|
+
time = value.is_a?(Time) ? value : MongoMapper.time_class.parse(value.to_s)
|
188
|
+
# Convert time to milliseconds since BSON stores dates with that accurracy, but Ruby uses microseconds
|
189
|
+
Time.at((time.to_f * 1000).round / 1000.0).utc if time
|
175
190
|
end
|
176
191
|
end
|
177
192
|
|
@@ -184,9 +199,17 @@ class Time
|
|
184
199
|
end
|
185
200
|
end
|
186
201
|
|
187
|
-
# TODO: Remove when patch accepted into driver
|
188
202
|
class Mongo::ObjectID
|
203
|
+
alias_method :original_to_json, :to_json
|
204
|
+
|
189
205
|
def to_json(options = nil)
|
190
206
|
%Q("#{to_s}")
|
191
207
|
end
|
192
|
-
end
|
208
|
+
end
|
209
|
+
|
210
|
+
module MongoMapper
|
211
|
+
module Support
|
212
|
+
autoload :DescendantAppends, 'mongo_mapper/support/descendant_appends'
|
213
|
+
autoload :Find, 'mongo_mapper/support/find'
|
214
|
+
end
|
215
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module MongoMapper
|
2
|
+
module Support
|
3
|
+
module DescendantAppends
|
4
|
+
def included(model)
|
5
|
+
extra_extensions.each { |extension| model.extend(extension) }
|
6
|
+
extra_inclusions.each { |inclusion| model.send(:include, inclusion) }
|
7
|
+
descendants << model
|
8
|
+
end
|
9
|
+
|
10
|
+
# @api public
|
11
|
+
def descendants
|
12
|
+
@descendants ||= Set.new
|
13
|
+
end
|
14
|
+
|
15
|
+
# @api public
|
16
|
+
def append_extensions(*extensions)
|
17
|
+
extra_extensions.concat extensions
|
18
|
+
|
19
|
+
# Add the extension to existing descendants
|
20
|
+
descendants.each do |model|
|
21
|
+
extensions.each { |extension| model.extend(extension) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# @api public
|
26
|
+
def append_inclusions(*inclusions)
|
27
|
+
extra_inclusions.concat inclusions
|
28
|
+
|
29
|
+
# Add the inclusion to existing descendants
|
30
|
+
descendants.each do |model|
|
31
|
+
inclusions.each { |inclusion| model.send(:include, inclusion) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# @api private
|
36
|
+
def extra_extensions
|
37
|
+
@extra_extensions ||= []
|
38
|
+
end
|
39
|
+
|
40
|
+
# @api private
|
41
|
+
def extra_inclusions
|
42
|
+
@extra_inclusions ||= []
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module MongoMapper
|
2
|
+
module Support
|
3
|
+
# @api private
|
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
|
+
|
27
|
+
class DynamicFinder
|
28
|
+
attr_reader :method, :attributes, :finder, :bang, :instantiator
|
29
|
+
|
30
|
+
def initialize(method)
|
31
|
+
@method = method
|
32
|
+
@finder = :first
|
33
|
+
@bang = false
|
34
|
+
match
|
35
|
+
end
|
36
|
+
|
37
|
+
def found?
|
38
|
+
@finder.present?
|
39
|
+
end
|
40
|
+
|
41
|
+
def raise?
|
42
|
+
bang == true
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
def match
|
47
|
+
case method.to_s
|
48
|
+
when /^find_(all_by|by)_([_a-zA-Z]\w*)$/
|
49
|
+
@finder = :all if $1 == 'all_by'
|
50
|
+
names = $2
|
51
|
+
when /^find_by_([_a-zA-Z]\w*)\!$/
|
52
|
+
@bang = true
|
53
|
+
names = $1
|
54
|
+
when /^find_or_(initialize|create)_by_([_a-zA-Z]\w*)$/
|
55
|
+
@instantiator = $1 == 'initialize' ? :new : :create
|
56
|
+
names = $2
|
57
|
+
else
|
58
|
+
@finder = nil
|
59
|
+
end
|
60
|
+
|
61
|
+
@attributes = names && names.split('_and_')
|
62
|
+
end
|
63
|
+
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
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/mongo_mapper.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongo_mapper}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.7.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["John Nunemaker"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-02-10}
|
13
13
|
s.default_executable = %q{mmconsole}
|
14
14
|
s.email = %q{nunemaker@gmail.com}
|
15
15
|
s.executables = ["mmconsole"]
|
@@ -25,35 +25,44 @@ Gem::Specification.new do |s|
|
|
25
25
|
"VERSION",
|
26
26
|
"bin/mmconsole",
|
27
27
|
"lib/mongo_mapper.rb",
|
28
|
-
"lib/mongo_mapper/associations.rb",
|
29
|
-
"lib/mongo_mapper/associations/base.rb",
|
30
|
-
"lib/mongo_mapper/associations/belongs_to_polymorphic_proxy.rb",
|
31
|
-
"lib/mongo_mapper/associations/belongs_to_proxy.rb",
|
32
|
-
"lib/mongo_mapper/associations/collection.rb",
|
33
|
-
"lib/mongo_mapper/associations/in_array_proxy.rb",
|
34
|
-
"lib/mongo_mapper/associations/many_documents_as_proxy.rb",
|
35
|
-
"lib/mongo_mapper/associations/many_documents_proxy.rb",
|
36
|
-
"lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb",
|
37
|
-
"lib/mongo_mapper/associations/many_embedded_proxy.rb",
|
38
|
-
"lib/mongo_mapper/associations/many_polymorphic_proxy.rb",
|
39
|
-
"lib/mongo_mapper/associations/one_proxy.rb",
|
40
|
-
"lib/mongo_mapper/associations/proxy.rb",
|
41
|
-
"lib/mongo_mapper/callbacks.rb",
|
42
|
-
"lib/mongo_mapper/dirty.rb",
|
43
28
|
"lib/mongo_mapper/document.rb",
|
44
|
-
"lib/mongo_mapper/dynamic_finder.rb",
|
45
29
|
"lib/mongo_mapper/embedded_document.rb",
|
46
|
-
"lib/mongo_mapper/
|
47
|
-
"lib/mongo_mapper/
|
48
|
-
"lib/mongo_mapper/
|
49
|
-
"lib/mongo_mapper/
|
50
|
-
"lib/mongo_mapper/
|
51
|
-
"lib/mongo_mapper/
|
52
|
-
"lib/mongo_mapper/
|
53
|
-
"lib/mongo_mapper/
|
30
|
+
"lib/mongo_mapper/plugins.rb",
|
31
|
+
"lib/mongo_mapper/plugins/associations.rb",
|
32
|
+
"lib/mongo_mapper/plugins/associations/base.rb",
|
33
|
+
"lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb",
|
34
|
+
"lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb",
|
35
|
+
"lib/mongo_mapper/plugins/associations/collection.rb",
|
36
|
+
"lib/mongo_mapper/plugins/associations/embedded_collection.rb",
|
37
|
+
"lib/mongo_mapper/plugins/associations/in_array_proxy.rb",
|
38
|
+
"lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb",
|
39
|
+
"lib/mongo_mapper/plugins/associations/many_documents_proxy.rb",
|
40
|
+
"lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb",
|
41
|
+
"lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb",
|
42
|
+
"lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb",
|
43
|
+
"lib/mongo_mapper/plugins/associations/one_proxy.rb",
|
44
|
+
"lib/mongo_mapper/plugins/associations/proxy.rb",
|
45
|
+
"lib/mongo_mapper/plugins/callbacks.rb",
|
46
|
+
"lib/mongo_mapper/plugins/clone.rb",
|
47
|
+
"lib/mongo_mapper/plugins/descendants.rb",
|
48
|
+
"lib/mongo_mapper/plugins/dirty.rb",
|
49
|
+
"lib/mongo_mapper/plugins/equality.rb",
|
50
|
+
"lib/mongo_mapper/plugins/identity_map.rb",
|
51
|
+
"lib/mongo_mapper/plugins/inspect.rb",
|
52
|
+
"lib/mongo_mapper/plugins/keys.rb",
|
53
|
+
"lib/mongo_mapper/plugins/logger.rb",
|
54
|
+
"lib/mongo_mapper/plugins/pagination.rb",
|
55
|
+
"lib/mongo_mapper/plugins/pagination/proxy.rb",
|
56
|
+
"lib/mongo_mapper/plugins/protected.rb",
|
57
|
+
"lib/mongo_mapper/plugins/rails.rb",
|
58
|
+
"lib/mongo_mapper/plugins/serialization.rb",
|
59
|
+
"lib/mongo_mapper/plugins/validations.rb",
|
60
|
+
"lib/mongo_mapper/query.rb",
|
54
61
|
"lib/mongo_mapper/support.rb",
|
55
|
-
"lib/mongo_mapper/
|
62
|
+
"lib/mongo_mapper/support/descendant_appends.rb",
|
63
|
+
"lib/mongo_mapper/support/find.rb",
|
56
64
|
"mongo_mapper.gemspec",
|
65
|
+
"performance/read_write.rb",
|
57
66
|
"specs.watchr",
|
58
67
|
"test/NOTE_ON_TESTING",
|
59
68
|
"test/functional/associations/test_belongs_to_polymorphic_proxy.rb",
|
@@ -71,10 +80,11 @@ Gem::Specification.new do |s|
|
|
71
80
|
"test/functional/test_dirty.rb",
|
72
81
|
"test/functional/test_document.rb",
|
73
82
|
"test/functional/test_embedded_document.rb",
|
83
|
+
"test/functional/test_identity_map.rb",
|
74
84
|
"test/functional/test_logger.rb",
|
75
85
|
"test/functional/test_modifiers.rb",
|
76
86
|
"test/functional/test_pagination.rb",
|
77
|
-
"test/functional/
|
87
|
+
"test/functional/test_protected.rb",
|
78
88
|
"test/functional/test_string_id_compatibility.rb",
|
79
89
|
"test/functional/test_validations.rb",
|
80
90
|
"test/models.rb",
|
@@ -84,15 +94,18 @@ Gem::Specification.new do |s|
|
|
84
94
|
"test/unit/associations/test_base.rb",
|
85
95
|
"test/unit/associations/test_proxy.rb",
|
86
96
|
"test/unit/serializers/test_json_serializer.rb",
|
97
|
+
"test/unit/test_descendant_appends.rb",
|
87
98
|
"test/unit/test_document.rb",
|
88
99
|
"test/unit/test_dynamic_finder.rb",
|
89
100
|
"test/unit/test_embedded_document.rb",
|
90
|
-
"test/unit/
|
91
|
-
"test/unit/test_key.rb",
|
101
|
+
"test/unit/test_keys.rb",
|
92
102
|
"test/unit/test_mongo_mapper.rb",
|
93
103
|
"test/unit/test_pagination.rb",
|
104
|
+
"test/unit/test_plugins.rb",
|
105
|
+
"test/unit/test_query.rb",
|
106
|
+
"test/unit/test_rails.rb",
|
94
107
|
"test/unit/test_rails_compatibility.rb",
|
95
|
-
"test/unit/
|
108
|
+
"test/unit/test_serialization.rb",
|
96
109
|
"test/unit/test_support.rb",
|
97
110
|
"test/unit/test_time_zones.rb",
|
98
111
|
"test/unit/test_validations.rb"
|
@@ -118,10 +131,11 @@ Gem::Specification.new do |s|
|
|
118
131
|
"test/functional/test_dirty.rb",
|
119
132
|
"test/functional/test_document.rb",
|
120
133
|
"test/functional/test_embedded_document.rb",
|
134
|
+
"test/functional/test_identity_map.rb",
|
121
135
|
"test/functional/test_logger.rb",
|
122
136
|
"test/functional/test_modifiers.rb",
|
123
137
|
"test/functional/test_pagination.rb",
|
124
|
-
"test/functional/
|
138
|
+
"test/functional/test_protected.rb",
|
125
139
|
"test/functional/test_string_id_compatibility.rb",
|
126
140
|
"test/functional/test_validations.rb",
|
127
141
|
"test/models.rb",
|
@@ -131,15 +145,18 @@ Gem::Specification.new do |s|
|
|
131
145
|
"test/unit/associations/test_base.rb",
|
132
146
|
"test/unit/associations/test_proxy.rb",
|
133
147
|
"test/unit/serializers/test_json_serializer.rb",
|
148
|
+
"test/unit/test_descendant_appends.rb",
|
134
149
|
"test/unit/test_document.rb",
|
135
150
|
"test/unit/test_dynamic_finder.rb",
|
136
151
|
"test/unit/test_embedded_document.rb",
|
137
|
-
"test/unit/
|
138
|
-
"test/unit/test_key.rb",
|
152
|
+
"test/unit/test_keys.rb",
|
139
153
|
"test/unit/test_mongo_mapper.rb",
|
140
154
|
"test/unit/test_pagination.rb",
|
155
|
+
"test/unit/test_plugins.rb",
|
156
|
+
"test/unit/test_query.rb",
|
157
|
+
"test/unit/test_rails.rb",
|
141
158
|
"test/unit/test_rails_compatibility.rb",
|
142
|
-
"test/unit/
|
159
|
+
"test/unit/test_serialization.rb",
|
143
160
|
"test/unit/test_support.rb",
|
144
161
|
"test/unit/test_time_zones.rb",
|
145
162
|
"test/unit/test_validations.rb"
|
@@ -151,7 +168,7 @@ Gem::Specification.new do |s|
|
|
151
168
|
|
152
169
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
153
170
|
s.add_runtime_dependency(%q<activesupport>, [">= 2.3"])
|
154
|
-
s.add_runtime_dependency(%q<mongo>, ["= 0.18.
|
171
|
+
s.add_runtime_dependency(%q<mongo>, ["= 0.18.3"])
|
155
172
|
s.add_runtime_dependency(%q<jnunemaker-validatable>, ["= 1.8.1"])
|
156
173
|
s.add_development_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
|
157
174
|
s.add_development_dependency(%q<shoulda>, ["= 2.10.2"])
|
@@ -159,7 +176,7 @@ Gem::Specification.new do |s|
|
|
159
176
|
s.add_development_dependency(%q<mocha>, ["= 0.9.8"])
|
160
177
|
else
|
161
178
|
s.add_dependency(%q<activesupport>, [">= 2.3"])
|
162
|
-
s.add_dependency(%q<mongo>, ["= 0.18.
|
179
|
+
s.add_dependency(%q<mongo>, ["= 0.18.3"])
|
163
180
|
s.add_dependency(%q<jnunemaker-validatable>, ["= 1.8.1"])
|
164
181
|
s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
|
165
182
|
s.add_dependency(%q<shoulda>, ["= 2.10.2"])
|
@@ -168,7 +185,7 @@ Gem::Specification.new do |s|
|
|
168
185
|
end
|
169
186
|
else
|
170
187
|
s.add_dependency(%q<activesupport>, [">= 2.3"])
|
171
|
-
s.add_dependency(%q<mongo>, ["= 0.18.
|
188
|
+
s.add_dependency(%q<mongo>, ["= 0.18.3"])
|
172
189
|
s.add_dependency(%q<jnunemaker-validatable>, ["= 1.8.1"])
|
173
190
|
s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
|
174
191
|
s.add_dependency(%q<shoulda>, ["= 2.10.2"])
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# The purpose of this is to check finding, initializing,
|
2
|
+
# and creating objects (typecasting times/dates and booleans).
|
3
|
+
|
4
|
+
require 'pp'
|
5
|
+
require 'benchmark'
|
6
|
+
require 'rubygems'
|
7
|
+
|
8
|
+
# to test with slow version just do this:
|
9
|
+
# gem 'mongo_mapper', '0.6.10'
|
10
|
+
# and comment out this:
|
11
|
+
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
12
|
+
|
13
|
+
require 'mongo_mapper'
|
14
|
+
|
15
|
+
MongoMapper.database = 'testing'
|
16
|
+
|
17
|
+
class Foo
|
18
|
+
include MongoMapper::Document
|
19
|
+
key :approved, Boolean
|
20
|
+
key :count, Integer
|
21
|
+
key :approved_at, Time
|
22
|
+
key :expire_on, Date
|
23
|
+
timestamps!
|
24
|
+
end
|
25
|
+
Foo.collection.remove
|
26
|
+
|
27
|
+
Benchmark.bm(5) do |x|
|
28
|
+
ids = []
|
29
|
+
x.report("write") do
|
30
|
+
1000.times { |i| ids << Foo.create(:count => 0, :approved => true, :approved_at => Time.now, :expire_on => Date.today).id }
|
31
|
+
end
|
32
|
+
|
33
|
+
x.report("read ") do
|
34
|
+
ids.each { |id| Foo.first(:id => id) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# I was get something like this on my puny macbook air:
|
39
|
+
# user system total real
|
40
|
+
# write 4.810000 0.090000 4.900000 ( 5.039949)
|
41
|
+
# read 2.730000 0.070000 2.800000 ( 2.990749)
|
42
|
+
#
|
43
|
+
#
|
44
|
+
# After these commits:
|
45
|
+
#
|
46
|
+
# * http://github.com/jnunemaker/mongomapper/commit/e5091fa140d5fae2721017b53027092233694ee5
|
47
|
+
# * http://github.com/jnunemaker/mongomapper/commit/c22bbde4fa1cfbc310d79cb0e50203310ffb03d1
|
48
|
+
#
|
49
|
+
# I'm now getting something like this:
|
50
|
+
# user system total real
|
51
|
+
# write 1.660000 0.050000 1.710000 ( 1.752676)
|
52
|
+
# read 1.060000 0.050000 1.110000 ( 1.263429)
|