mongo_mapper_ign 0.7.4 → 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.
Files changed (102) hide show
  1. data/README.rdoc +1 -1
  2. data/lib/mongo_mapper.rb +5 -8
  3. data/lib/mongo_mapper/document.rb +24 -53
  4. data/lib/mongo_mapper/embedded_document.rb +1 -0
  5. data/lib/mongo_mapper/plugins.rb +1 -0
  6. data/lib/mongo_mapper/plugins/associations.rb +2 -1
  7. data/lib/mongo_mapper/plugins/associations/base.rb +5 -4
  8. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +2 -1
  9. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +2 -1
  10. data/lib/mongo_mapper/plugins/associations/collection.rb +1 -0
  11. data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +1 -0
  12. data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +1 -0
  13. data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +1 -0
  14. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +2 -1
  15. data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +1 -0
  16. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +1 -0
  17. data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +1 -0
  18. data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +1 -0
  19. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +2 -1
  20. data/lib/mongo_mapper/plugins/associations/proxy.rb +1 -0
  21. data/lib/mongo_mapper/plugins/callbacks.rb +1 -0
  22. data/lib/mongo_mapper/plugins/clone.rb +1 -0
  23. data/lib/mongo_mapper/plugins/descendants.rb +1 -0
  24. data/lib/mongo_mapper/plugins/dirty.rb +1 -0
  25. data/lib/mongo_mapper/plugins/equality.rb +4 -3
  26. data/lib/mongo_mapper/plugins/identity_map.rb +9 -7
  27. data/lib/mongo_mapper/plugins/inspect.rb +1 -0
  28. data/lib/mongo_mapper/plugins/keys.rb +50 -73
  29. data/lib/mongo_mapper/plugins/keys/key.rb +54 -0
  30. data/lib/mongo_mapper/plugins/logger.rb +1 -0
  31. data/lib/mongo_mapper/plugins/modifiers.rb +10 -5
  32. data/lib/mongo_mapper/plugins/pagination.rb +1 -0
  33. data/lib/mongo_mapper/plugins/pagination/proxy.rb +4 -3
  34. data/lib/mongo_mapper/plugins/persistence.rb +1 -0
  35. data/lib/mongo_mapper/plugins/protected.rb +1 -0
  36. data/lib/mongo_mapper/plugins/rails.rb +1 -0
  37. data/lib/mongo_mapper/plugins/serialization.rb +4 -3
  38. data/lib/mongo_mapper/plugins/timestamps.rb +2 -1
  39. data/lib/mongo_mapper/plugins/userstamps.rb +1 -0
  40. data/lib/mongo_mapper/plugins/validations.rb +3 -2
  41. data/lib/mongo_mapper/query.rb +10 -129
  42. data/lib/mongo_mapper/support.rb +18 -39
  43. data/lib/mongo_mapper/support/descendant_appends.rb +1 -0
  44. data/lib/mongo_mapper/support/find.rb +1 -0
  45. data/lib/mongo_mapper/version.rb +2 -1
  46. metadata +32 -134
  47. data/.gitignore +0 -10
  48. data/Rakefile +0 -37
  49. data/mongo_mapper.gemspec +0 -214
  50. data/mongo_mapper_ign.gemspec +0 -217
  51. data/performance/read_write.rb +0 -52
  52. data/specs.watchr +0 -51
  53. data/test/NOTE_ON_TESTING +0 -1
  54. data/test/active_model_lint_test.rb +0 -13
  55. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +0 -63
  56. data/test/functional/associations/test_belongs_to_proxy.rb +0 -101
  57. data/test/functional/associations/test_in_array_proxy.rb +0 -325
  58. data/test/functional/associations/test_many_documents_as_proxy.rb +0 -229
  59. data/test/functional/associations/test_many_documents_proxy.rb +0 -536
  60. data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +0 -176
  61. data/test/functional/associations/test_many_embedded_proxy.rb +0 -256
  62. data/test/functional/associations/test_many_polymorphic_proxy.rb +0 -302
  63. data/test/functional/associations/test_one_embedded_proxy.rb +0 -68
  64. data/test/functional/associations/test_one_proxy.rb +0 -196
  65. data/test/functional/test_associations.rb +0 -44
  66. data/test/functional/test_binary.rb +0 -27
  67. data/test/functional/test_callbacks.rb +0 -151
  68. data/test/functional/test_dirty.rb +0 -163
  69. data/test/functional/test_document.rb +0 -1219
  70. data/test/functional/test_embedded_document.rb +0 -210
  71. data/test/functional/test_identity_map.rb +0 -507
  72. data/test/functional/test_indexing.rb +0 -44
  73. data/test/functional/test_logger.rb +0 -20
  74. data/test/functional/test_modifiers.rb +0 -394
  75. data/test/functional/test_pagination.rb +0 -93
  76. data/test/functional/test_protected.rb +0 -163
  77. data/test/functional/test_string_id_compatibility.rb +0 -67
  78. data/test/functional/test_timestamps.rb +0 -64
  79. data/test/functional/test_userstamps.rb +0 -28
  80. data/test/functional/test_validations.rb +0 -342
  81. data/test/models.rb +0 -227
  82. data/test/support/custom_matchers.rb +0 -37
  83. data/test/support/timing.rb +0 -16
  84. data/test/test_helper.rb +0 -64
  85. data/test/unit/associations/test_base.rb +0 -212
  86. data/test/unit/associations/test_proxy.rb +0 -105
  87. data/test/unit/serializers/test_json_serializer.rb +0 -202
  88. data/test/unit/test_descendant_appends.rb +0 -71
  89. data/test/unit/test_document.rb +0 -225
  90. data/test/unit/test_dynamic_finder.rb +0 -123
  91. data/test/unit/test_embedded_document.rb +0 -657
  92. data/test/unit/test_keys.rb +0 -185
  93. data/test/unit/test_mongo_mapper.rb +0 -118
  94. data/test/unit/test_pagination.rb +0 -160
  95. data/test/unit/test_plugins.rb +0 -50
  96. data/test/unit/test_query.rb +0 -374
  97. data/test/unit/test_rails.rb +0 -181
  98. data/test/unit/test_rails_compatibility.rb +0 -52
  99. data/test/unit/test_serialization.rb +0 -51
  100. data/test/unit/test_support.rb +0 -382
  101. data/test/unit/test_time_zones.rb +0 -39
  102. data/test/unit/test_validations.rb +0 -544
@@ -14,7 +14,7 @@ Releases are tagged on github and released on gemcutter. Master is pushed to whe
14
14
 
15
15
  == Install
16
16
 
17
- $ gem install mongo_mapper
17
+ $ gem install mongo_mapper_ign
18
18
 
19
19
  == Config Rails environment.rb
20
20
 
@@ -1,10 +1,8 @@
1
- # Make sure you have the following libs in your load path or you could have issues:
2
- # gem 'activesupport', '>= 2.3.4'
3
- # gem 'mongo', '0.20.1'
4
- # gem 'jnunemaker-validatable', '1.8.4'
1
+ # encoding: UTF-8
2
+ # Make sure you have the correct versions of the gems (see gemspec) in your load path.
5
3
  require 'set'
6
4
  require 'uri'
7
- require 'mongo'
5
+ require 'plucky'
8
6
  require 'validatable'
9
7
  require 'active_support/all'
10
8
 
@@ -71,7 +69,7 @@ module MongoMapper
71
69
  def self.config_for_environment(environment)
72
70
  env = config[environment]
73
71
  return env if env['uri'].blank?
74
-
72
+
75
73
  uri = URI.parse(env['uri'])
76
74
  raise InvalidScheme.new('must be mongodb') unless uri.scheme == 'mongodb'
77
75
  {
@@ -92,8 +90,7 @@ module MongoMapper
92
90
  end
93
91
 
94
92
  def self.setup(config, environment, options={})
95
- using_passenger = options.delete(:passenger)
96
- handle_passenger_forking if using_passenger
93
+ handle_passenger_forking
97
94
  self.config = config
98
95
  connect(environment, options)
99
96
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Document
3
4
  extend Support::DescendantAppends
@@ -45,34 +46,31 @@ module MongoMapper
45
46
  end
46
47
 
47
48
  def find(*args)
48
- assert_no_first_last_or_all(args)
49
49
  options = args.extract_options!
50
50
  return nil if args.size == 0
51
51
 
52
52
  if args.first.is_a?(Array) || args.size > 1
53
53
  find_some(args, options)
54
54
  else
55
- find_one(options.merge({:_id => args[0]}))
55
+ query = query(options).update(:_id => args[0])
56
+ find_one(query.to_hash)
56
57
  end
57
58
  end
58
59
 
59
60
  def find!(*args)
60
- assert_no_first_last_or_all(args)
61
61
  options = args.extract_options!
62
62
  raise DocumentNotFound, "Couldn't find without an ID" if args.size == 0
63
63
 
64
64
  if args.first.is_a?(Array) || args.size > 1
65
65
  find_some!(args, options)
66
66
  else
67
- find_one(options.merge({:_id => args[0]})) || raise(DocumentNotFound, "Document match #{options.inspect} does not exist in #{collection.name} collection")
67
+ query = query(options).update(:_id => args[0])
68
+ find_one(query.to_hash) || raise(DocumentNotFound, "Document match #{options.inspect} does not exist in #{collection.name} collection")
68
69
  end
69
70
  end
70
71
 
71
72
  def find_each(options={})
72
- criteria, options = to_query(options)
73
- collection.find(criteria, options).each do |doc|
74
- yield load(doc)
75
- end
73
+ query(options).find().each { |doc| yield load(doc) }
76
74
  end
77
75
 
78
76
  def find_by_id(id)
@@ -93,7 +91,7 @@ module MongoMapper
93
91
 
94
92
  def last(options={})
95
93
  raise ':order option must be provided when using last' if options[:order].blank?
96
- find_one(options.merge(:order => invert_order_clause(options[:order])))
94
+ find_one(query(options).reverse.to_hash)
97
95
  end
98
96
 
99
97
  def all(options={})
@@ -101,7 +99,7 @@ module MongoMapper
101
99
  end
102
100
 
103
101
  def count(options={})
104
- collection.find(to_criteria(options)).count
102
+ query(options).count
105
103
  end
106
104
 
107
105
  def exists?(options={})
@@ -126,11 +124,11 @@ module MongoMapper
126
124
  end
127
125
 
128
126
  def delete(*ids)
129
- collection.remove(to_criteria(:_id => ids.flatten))
127
+ query(:_id => ids.flatten).remove
130
128
  end
131
129
 
132
130
  def delete_all(options={})
133
- collection.remove(to_criteria(options))
131
+ query(options).remove
134
132
  end
135
133
 
136
134
  def destroy(*ids)
@@ -153,6 +151,11 @@ module MongoMapper
153
151
  superclass.respond_to?(:keys) && superclass.keys.key?(:_type)
154
152
  end
155
153
 
154
+ # @api private for now
155
+ def query(options={})
156
+ Query.new(self, options)
157
+ end
158
+
156
159
  private
157
160
  def initialize_each(*docs)
158
161
  instances = []
@@ -165,15 +168,9 @@ module MongoMapper
165
168
  instances.size == 1 ? instances[0] : instances
166
169
  end
167
170
 
168
- def assert_no_first_last_or_all(args)
169
- if args[0] == :first || args[0] == :last || args[0] == :all
170
- raise ArgumentError, "#{self}.find(:#{args}) is no longer supported, use #{self}.#{args} instead."
171
- end
172
- end
173
-
174
171
  def find_some(ids, options={})
175
- ids = ids.flatten.compact.uniq
176
- find_many(options.merge(:_id => ids)).compact
172
+ query = query(options).update(:_id => ids.flatten.compact.uniq)
173
+ find_many(query.to_hash).compact
177
174
  end
178
175
 
179
176
  def find_some!(ids, options={})
@@ -189,30 +186,12 @@ module MongoMapper
189
186
 
190
187
  # All query methods that load documents pass through find_one or find_many
191
188
  def find_one(options={})
192
- criteria, options = to_query(options)
193
- if doc = collection.find_one(criteria, options)
194
- load(doc)
195
- end
189
+ load(query(options).first)
196
190
  end
197
191
 
198
192
  # All query methods that load documents pass through find_one or find_many
199
193
  def find_many(options)
200
- criteria, options = to_query(options)
201
- collection.find(criteria, options).to_a.map do |doc|
202
- load(doc)
203
- end
204
- end
205
-
206
- def invert_order_clause(order)
207
- order.split(',').map do |order_segment|
208
- if order_segment =~ /\sasc/i
209
- order_segment.sub /\sasc/i, ' desc'
210
- elsif order_segment =~ /\sdesc/i
211
- order_segment.sub /\sdesc/i, ' asc'
212
- else
213
- "#{order_segment.strip} desc"
214
- end
215
- end.join(',')
194
+ query(options).all().map { |doc| load(doc) }
216
195
  end
217
196
 
218
197
  def update_single(id, attrs)
@@ -220,9 +199,9 @@ module MongoMapper
220
199
  raise ArgumentError, "Updating a single document requires an id and a hash of attributes"
221
200
  end
222
201
 
223
- doc = find(id)
224
- doc.update_attributes(attrs)
225
- doc
202
+ find(id).tap do |doc|
203
+ doc.update_attributes(attrs)
204
+ end
226
205
  end
227
206
 
228
207
  def update_multiple(docs)
@@ -234,14 +213,6 @@ module MongoMapper
234
213
  docs.each_pair { |id, attrs| instances << update(id, attrs) }
235
214
  instances
236
215
  end
237
-
238
- def to_criteria(options={})
239
- Query.new(self, options).criteria
240
- end
241
-
242
- def to_query(options={})
243
- Query.new(self, options).to_a
244
- end
245
216
  end
246
217
 
247
218
  module InstanceMethods
@@ -274,9 +245,9 @@ module MongoMapper
274
245
  end
275
246
 
276
247
  def reload
277
- if attrs = collection.find_one({:_id => _id})
248
+ if doc = self.class.query(:_id => id).first
278
249
  self.class.associations.each { |name, assoc| send(name).reset if respond_to?(name) }
279
- self.attributes = attrs
250
+ self.attributes = doc
280
251
  self
281
252
  else
282
253
  raise DocumentNotFound, "Document match #{_id.inspect} does not exist in #{collection.name} collection"
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module EmbeddedDocument
3
4
  extend Support::DescendantAppends
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  def plugins
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  module Associations
@@ -84,7 +85,7 @@ module MongoMapper
84
85
 
85
86
  proxy
86
87
  end
87
-
88
+
88
89
  def save_to_collection(options = {})
89
90
  super
90
91
  associations.each do |association_name, association|
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  module Associations
@@ -16,8 +17,8 @@ module MongoMapper
16
17
 
17
18
  def class_name
18
19
  return @class_name if defined?(@class_name)
19
-
20
- @class_name =
20
+
21
+ @class_name =
21
22
  if cn = options[:class_name]
22
23
  cn
23
24
  elsif many?
@@ -78,8 +79,8 @@ module MongoMapper
78
79
  # hate this, need to revisit
79
80
  def proxy_class
80
81
  return @proxy_class if defined?(@proxy_class)
81
-
82
- @proxy_class =
82
+
83
+ @proxy_class =
83
84
  if many?
84
85
  if klass.embeddable?
85
86
  polymorphic? ? ManyEmbeddedPolymorphicProxy : ManyEmbeddedProxy
@@ -1,9 +1,10 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  module Associations
4
5
  class BelongsToPolymorphicProxy < Proxy
5
6
  undef_method :object_id
6
-
7
+
7
8
  def replace(doc)
8
9
  if doc
9
10
  doc.save if doc.new?
@@ -1,9 +1,10 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  module Associations
4
5
  class BelongsToProxy < Proxy
5
6
  undef_method :object_id
6
-
7
+
7
8
  def replace(doc)
8
9
  if doc
9
10
  doc.save if doc.new?
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  module Associations
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  module Associations
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  module Associations
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  module Associations
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  module Associations
@@ -88,7 +89,7 @@ module MongoMapper
88
89
  end
89
90
  reset
90
91
  end
91
-
92
+
92
93
  def save_to_collection(options = {})
93
94
  @target.each { |doc| doc.save(options) } if @target
94
95
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  module Associations
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  module Associations
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  module Associations
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  module Associations
@@ -1,9 +1,10 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  module Associations
4
5
  class OneProxy < Proxy
5
6
  undef_method :object_id
6
-
7
+
7
8
  def build(attrs={})
8
9
  instantiate_target(:new, attrs)
9
10
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  module Associations
@@ -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.
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  module Clone
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  module Descendants
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  module Dirty
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  module Equality
@@ -5,15 +6,15 @@ module MongoMapper
5
6
  def ==(other)
6
7
  other.is_a?(self.class) && _id == other._id
7
8
  end
8
-
9
+
9
10
  def eql?(other)
10
11
  self == other
11
12
  end
12
-
13
+
13
14
  def equal?(other)
14
15
  object_id === other.object_id
15
16
  end
16
-
17
+
17
18
  def hash
18
19
  _id.hash
19
20
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module MongoMapper
2
3
  module Plugins
3
4
  module IdentityMap
@@ -8,7 +9,7 @@ module MongoMapper
8
9
  def self.clear
9
10
  models.each { |m| m.identity_map.clear }
10
11
  end
11
-
12
+
12
13
  def self.configure(model)
13
14
  IdentityMap.models << model
14
15
  end
@@ -28,27 +29,28 @@ module MongoMapper
28
29
  end
29
30
 
30
31
  def find_one(options={})
31
- criteria, query_options = to_query(options)
32
-
32
+ query = query(options)
33
+ criteria = query.criteria.to_hash
34
+
33
35
  if simple_find?(criteria) && identity_map.key?(criteria[:_id])
34
36
  identity_map[criteria[:_id]]
35
37
  else
36
38
  super.tap do |document|
37
- remove_documents_from_map(document) if selecting_fields?(query_options)
39
+ remove_documents_from_map(document) if selecting_fields?(query.options)
38
40
  end
39
41
  end
40
42
  end
41
43
 
42
44
  def find_many(options)
43
- criteria, query_options = to_query(options)
44
45
  super.tap do |documents|
45
- remove_documents_from_map(documents) if selecting_fields?(query_options)
46
+ remove_documents_from_map(documents) if selecting_fields?(query(options).options)
46
47
  end
47
48
  end
48
49
 
49
50
  def load(attrs)
51
+ return nil if attrs.nil?
50
52
  document = identity_map[attrs['_id']]
51
-
53
+
52
54
  if document.nil? || identity_map_off?
53
55
  document = super
54
56
  identity_map[document._id] = document if identity_map_on?