mongo_mapper 0.13.1 → 0.14.0.rc1

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 (103) hide show
  1. checksums.yaml +13 -5
  2. data/README.rdoc +3 -6
  3. data/lib/mongo_mapper.rb +1 -0
  4. data/lib/mongo_mapper/document.rb +2 -0
  5. data/lib/mongo_mapper/extensions/array.rb +14 -6
  6. data/lib/mongo_mapper/extensions/hash.rb +15 -3
  7. data/lib/mongo_mapper/extensions/object.rb +4 -0
  8. data/lib/mongo_mapper/extensions/string.rb +13 -5
  9. data/lib/mongo_mapper/plugins/accessible.rb +12 -11
  10. data/lib/mongo_mapper/plugins/associations.rb +7 -6
  11. data/lib/mongo_mapper/plugins/associations/base.rb +13 -12
  12. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +9 -8
  13. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +12 -11
  14. data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +4 -4
  15. data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +24 -23
  16. data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +18 -16
  17. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +55 -48
  18. data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +14 -13
  19. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +7 -6
  20. data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +7 -5
  21. data/lib/mongo_mapper/plugins/associations/one_as_proxy.rb +14 -11
  22. data/lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb +14 -13
  23. data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +9 -9
  24. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +27 -26
  25. data/lib/mongo_mapper/plugins/associations/proxy.rb +29 -26
  26. data/lib/mongo_mapper/plugins/callbacks.rb +13 -0
  27. data/lib/mongo_mapper/plugins/counter_cache.rb +23 -4
  28. data/lib/mongo_mapper/plugins/dirty.rb +2 -2
  29. data/lib/mongo_mapper/plugins/dynamic_querying.rb +10 -9
  30. data/lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb +17 -16
  31. data/lib/mongo_mapper/plugins/embedded_callbacks.rb +1 -1
  32. data/lib/mongo_mapper/plugins/identity_map.rb +1 -1
  33. data/lib/mongo_mapper/plugins/indexes.rb +1 -1
  34. data/lib/mongo_mapper/plugins/keys.rb +158 -158
  35. data/lib/mongo_mapper/plugins/keys/key.rb +16 -10
  36. data/lib/mongo_mapper/plugins/keys/static.rb +45 -0
  37. data/lib/mongo_mapper/plugins/modifiers.rb +27 -26
  38. data/lib/mongo_mapper/plugins/partial_updates.rb +86 -0
  39. data/lib/mongo_mapper/plugins/persistence.rb +7 -6
  40. data/lib/mongo_mapper/plugins/protected.rb +6 -5
  41. data/lib/mongo_mapper/plugins/querying.rb +80 -43
  42. data/lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb +14 -9
  43. data/lib/mongo_mapper/plugins/scopes.rb +78 -7
  44. data/lib/mongo_mapper/plugins/timestamps.rb +1 -0
  45. data/lib/mongo_mapper/plugins/validations.rb +0 -0
  46. data/lib/mongo_mapper/version.rb +1 -1
  47. data/lib/rails/generators/mongo_mapper/config/config_generator.rb +12 -13
  48. data/lib/rails/generators/mongo_mapper/model/model_generator.rb +9 -9
  49. data/spec/functional/accessible_spec.rb +12 -12
  50. data/spec/functional/associations/belongs_to_polymorphic_proxy_spec.rb +11 -11
  51. data/spec/functional/associations/belongs_to_proxy_spec.rb +14 -15
  52. data/spec/functional/associations/in_array_proxy_spec.rb +6 -6
  53. data/spec/functional/associations/many_documents_proxy_spec.rb +89 -18
  54. data/spec/functional/associations/many_embedded_polymorphic_proxy_spec.rb +11 -11
  55. data/spec/functional/associations/many_embedded_proxy_spec.rb +1 -1
  56. data/spec/functional/associations/one_as_proxy_spec.rb +14 -14
  57. data/spec/functional/associations/one_embedded_polymorphic_proxy_spec.rb +9 -9
  58. data/spec/functional/associations/one_embedded_proxy_spec.rb +3 -3
  59. data/spec/functional/associations/one_proxy_spec.rb +14 -14
  60. data/spec/functional/caching_spec.rb +8 -8
  61. data/spec/functional/callbacks_spec.rb +87 -0
  62. data/spec/functional/counter_cache_spec.rb +89 -0
  63. data/spec/functional/dirty_spec.rb +41 -41
  64. data/spec/functional/document_spec.rb +3 -3
  65. data/spec/functional/embedded_document_spec.rb +18 -18
  66. data/spec/functional/identity_map_spec.rb +28 -15
  67. data/spec/functional/indexes_spec.rb +4 -4
  68. data/spec/functional/keys_spec.rb +12 -3
  69. data/spec/functional/logger_spec.rb +1 -1
  70. data/spec/functional/modifiers_spec.rb +2 -2
  71. data/spec/functional/partial_updates_spec.rb +577 -0
  72. data/spec/functional/protected_spec.rb +13 -13
  73. data/spec/functional/querying_spec.rb +11 -10
  74. data/spec/functional/safe_spec.rb +2 -2
  75. data/spec/functional/sci_spec.rb +3 -3
  76. data/spec/functional/scopes_spec.rb +234 -1
  77. data/spec/functional/static_keys_spec.rb +153 -0
  78. data/spec/functional/stats_spec.rb +0 -4
  79. data/spec/functional/touch_spec.rb +1 -1
  80. data/spec/functional/validations_spec.rb +59 -57
  81. data/spec/quality_spec.rb +1 -1
  82. data/spec/spec_helper.rb +7 -3
  83. data/spec/support/matchers.rb +4 -13
  84. data/spec/unit/associations/base_spec.rb +12 -12
  85. data/spec/unit/associations/belongs_to_association_spec.rb +2 -2
  86. data/spec/unit/associations/many_association_spec.rb +2 -2
  87. data/spec/unit/associations/one_association_spec.rb +2 -2
  88. data/spec/unit/associations/proxy_spec.rb +13 -15
  89. data/spec/unit/document_spec.rb +5 -5
  90. data/spec/unit/dynamic_finder_spec.rb +8 -8
  91. data/spec/unit/embedded_document_spec.rb +14 -14
  92. data/spec/unit/extensions_spec.rb +17 -17
  93. data/spec/unit/identity_map_middleware_spec.rb +5 -5
  94. data/spec/unit/key_spec.rb +24 -21
  95. data/spec/unit/keys_spec.rb +5 -5
  96. data/spec/unit/mongo_mapper_spec.rb +26 -26
  97. data/spec/unit/rails_spec.rb +2 -2
  98. data/spec/unit/serialization_spec.rb +1 -1
  99. data/spec/unit/time_zones_spec.rb +2 -2
  100. data/spec/unit/validations_spec.rb +28 -15
  101. metadata +16 -14
  102. data/lib/mongo_mapper/connections/10gen.rb +0 -0
  103. data/lib/mongo_mapper/connections/moped.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3e78985587a63e18283384630db3c316ee260b20
4
- data.tar.gz: 5f2d55cbe5df4c2f8322088cb9f0edfaa84a69e9
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDZhYzcyYjE1YmNiYTY4NTVlOGFiZjRlNjk1MTVjOWRkZWViODE3YQ==
5
+ data.tar.gz: !binary |-
6
+ YjUxMmRlMTUyOTM5ZjgwMTBlM2JlMzFjNWIxNTVjYWY4NDU3NTYxMA==
5
7
  SHA512:
6
- metadata.gz: cf19d01f18a16676486f87db3e0db2c6894c6542f8492ed63b72cd9dbb24ae4dd90f26c5ec226a98fdc1636539a5a9a410c813bffba5923fa95a06fcc873bc4b
7
- data.tar.gz: 0b915ec964c1bafa1c3432061d91800029f291ce7799945830129d5c4109b1c2c21902ed8eb31ebb6c5648cb46c4775fe692d46614078ba001dabc95606ca3d0
8
+ metadata.gz: !binary |-
9
+ N2ZhNWM1NmZlOTE3NDYwYjExZTZhODcxMTM1YzM3Yzg4NTY4ZjFlOTk4NDA1
10
+ NGJkNDc3YTdhZWRiY2JlOWZjNWZjNDZjYjkzMzZlMmNkY2MxNWNjZTE4M2Q3
11
+ OWYzYjBjNjcxNTVkODg4OTliODY5NTZjYWE1NzBjZGE1ZGU0NDA=
12
+ data.tar.gz: !binary |-
13
+ OWMyYjNmNTY5ZGNhOTM1MGNkNTg0MGFkNzkwMjg3Yjc5Y2M0MzM2ZjUwNTZm
14
+ YjU1MjAxODYzOTllYzM4NzBjZjNmYmI2NGUzYWFiODQwMjNmN2E4MDAxYWYz
15
+ MjQyNGQ4ZmU1OTcwMmRmOGZlMWQ4NDI1ZTJjYjU4ODViMjM4OWQ=
@@ -14,7 +14,7 @@ A Ruby Object Mapper for Mongo.
14
14
 
15
15
  http://mongomapper.com/documentation/
16
16
 
17
- http://rdoc.info/github/jnunemaker/mongomapper
17
+ http://rdoc.info/github/mongomapper/mongomapper
18
18
 
19
19
  == Compatibility
20
20
 
@@ -23,6 +23,7 @@ MongoMapper is tested against:
23
23
  * MRI 1.8.7
24
24
  * MRI 1.9.3
25
25
  * MRI 2.0.0
26
+ * MRI 2.1.1
26
27
  * JRuby (Versions with 1.9 compatibility)
27
28
 
28
29
  Additionally, MongoMapper is tested against:
@@ -32,13 +33,9 @@ Additionally, MongoMapper is tested against:
32
33
  * Rails 3.2.x
33
34
  * Rails 4.0.x
34
35
 
35
- NOTE: Rails 4 support is only in the v0.13.0 beta, which is not currently the default in RubyGems. Use the following line in your gemfile to use the beta:
36
-
37
- gem 'mongo_mapper', :git => "git://github.com/mongomapper/mongomapper.git", :tag => "v0.13.0.beta2"
38
-
39
36
  == Contributing & Development
40
37
 
41
- $ git clone https://github.com/jnunemaker/mongomapper && cd mongomapper
38
+ $ git clone https://github.com/mongomapper/mongomapper && cd mongomapper
42
39
  $ bundle install
43
40
  $ bundle exec rake
44
41
 
@@ -51,6 +51,7 @@ module MongoMapper
51
51
  autoload :Logger, 'mongo_mapper/plugins/logger'
52
52
  autoload :Modifiers, 'mongo_mapper/plugins/modifiers'
53
53
  autoload :Pagination, 'mongo_mapper/plugins/pagination'
54
+ autoload :PartialUpdates, 'mongo_mapper/plugins/partial_updates'
54
55
  autoload :Persistence, 'mongo_mapper/plugins/persistence'
55
56
  autoload :Protected, 'mongo_mapper/plugins/protected'
56
57
  autoload :Querying, 'mongo_mapper/plugins/querying'
@@ -16,6 +16,7 @@ module MongoMapper
16
16
  include Plugins::Inspect
17
17
  include Plugins::Indexes
18
18
  include Plugins::Keys
19
+ include Plugins::Keys::Static
19
20
  include Plugins::Dirty # for now dirty needs to be after keys
20
21
  include Plugins::Logger
21
22
  include Plugins::Modifiers
@@ -35,6 +36,7 @@ module MongoMapper
35
36
  include Plugins::Validations
36
37
  include Plugins::EmbeddedCallbacks
37
38
  include Plugins::Callbacks # for now callbacks needs to be after validations
39
+ include Plugins::PartialUpdates
38
40
  include Plugins::IdentityMap
39
41
  include Plugins::CounterCache
40
42
 
@@ -2,18 +2,26 @@
2
2
  module MongoMapper
3
3
  module Extensions
4
4
  module Array
5
- def to_mongo(value)
6
- value = value.respond_to?(:lines) ? value.lines : value
7
- value.to_a
5
+ extend ActiveSupport::Concern
6
+
7
+ module ClassMethods
8
+ def to_mongo(value)
9
+ value = value.respond_to?(:lines) ? value.lines : value
10
+ value.to_a
11
+ end
12
+
13
+ def from_mongo(value)
14
+ value || []
15
+ end
8
16
  end
9
17
 
10
- def from_mongo(value)
11
- value || []
18
+ def _mongo_mapper_deep_copy_
19
+ map { |value| value._mongo_mapper_deep_copy_ }
12
20
  end
13
21
  end
14
22
  end
15
23
  end
16
24
 
17
25
  class Array
18
- extend MongoMapper::Extensions::Array
26
+ include MongoMapper::Extensions::Array
19
27
  end
@@ -2,13 +2,25 @@
2
2
  module MongoMapper
3
3
  module Extensions
4
4
  module Hash
5
- def from_mongo(value)
6
- HashWithIndifferentAccess.new(value || {})
5
+ extend ActiveSupport::Concern
6
+
7
+ module ClassMethods
8
+ def from_mongo(value)
9
+ HashWithIndifferentAccess.new(value || {})
10
+ end
11
+ end
12
+
13
+ def _mongo_mapper_deep_copy_
14
+ self.class.new.tap do |new_hash|
15
+ each do |key, value|
16
+ new_hash[key._mongo_mapper_deep_copy_] = value._mongo_mapper_deep_copy_
17
+ end
18
+ end
7
19
  end
8
20
  end
9
21
  end
10
22
  end
11
23
 
12
24
  class Hash
13
- extend MongoMapper::Extensions::Hash
25
+ include MongoMapper::Extensions::Hash
14
26
  end
@@ -17,6 +17,10 @@ module MongoMapper
17
17
  def to_mongo
18
18
  self.class.to_mongo(self)
19
19
  end
20
+
21
+ def _mongo_mapper_deep_copy_
22
+ self
23
+ end
20
24
  end
21
25
  end
22
26
  end
@@ -2,17 +2,25 @@
2
2
  module MongoMapper
3
3
  module Extensions
4
4
  module String
5
- def to_mongo(value)
6
- value && value.to_s
5
+ extend ActiveSupport::Concern
6
+
7
+ module ClassMethods
8
+ def to_mongo(value)
9
+ value && value.to_s
10
+ end
11
+
12
+ def from_mongo(value)
13
+ value && value.to_s
14
+ end
7
15
  end
8
16
 
9
- def from_mongo(value)
10
- value && value.to_s
17
+ def _mongo_mapper_deep_copy_
18
+ self.dup
11
19
  end
12
20
  end
13
21
  end
14
22
  end
15
23
 
16
24
  class String
17
- extend MongoMapper::Extensions::String
25
+ include MongoMapper::Extensions::String
18
26
  end
@@ -42,20 +42,21 @@ module MongoMapper
42
42
  self.class.accessible_attributes?
43
43
  end
44
44
 
45
- protected
46
- def filter_inaccessible_attrs(attrs)
47
- return attrs if !accessible_attributes? || attrs.blank?
48
- attrs.dup.delete_if { |key, val| attribute_inaccessible?(key.to_sym) }
49
- end
45
+ protected
46
+
47
+ def filter_inaccessible_attrs(attrs)
48
+ return attrs if !accessible_attributes? || attrs.blank?
49
+ attrs.dup.delete_if { |key, val| attribute_inaccessible?(key.to_sym) }
50
+ end
50
51
 
51
- def attribute_inaccessible?(attribute)
52
- unless accessible_attributes.include?(attribute)
53
- message = "Can't mass-assign protected attribute: #{attribute}"
54
- MongoMapper.logger ? MongoMapper.logger.warn(message) : puts(message)
52
+ def attribute_inaccessible?(attribute)
53
+ unless accessible_attributes.include?(attribute)
54
+ message = "Can't mass-assign protected attribute: #{attribute}"
55
+ MongoMapper.logger ? MongoMapper.logger.warn(message) : puts(message)
55
56
 
56
- return true
57
- end
57
+ return true
58
58
  end
59
+ end
59
60
  end
60
61
  end
61
62
  end
@@ -56,12 +56,13 @@ module MongoMapper
56
56
  end
57
57
  end
58
58
 
59
- private
60
- def create_association(association)
61
- @embedded_associations = nil
62
- associations[association.name] = association
63
- association.setup(self)
64
- end
59
+ private
60
+
61
+ def create_association(association)
62
+ @embedded_associations = nil
63
+ associations[association.name] = association
64
+ association.setup(self)
65
+ end
65
66
  end
66
67
 
67
68
  def associations
@@ -76,22 +76,23 @@ module MongoMapper
76
76
  def setup(model)
77
77
  end
78
78
 
79
- private
80
- def separate_options_and_conditions
81
- @original_options.each_pair do |key, value|
82
- if AssociationOptions.include?(key)
83
- @options[key] = value
84
- else
85
- @query_options[key] = value
86
- end
79
+ private
80
+
81
+ def separate_options_and_conditions
82
+ @original_options.each_pair do |key, value|
83
+ if AssociationOptions.include?(key)
84
+ @options[key] = value
85
+ else
86
+ @query_options[key] = value
87
87
  end
88
88
  end
89
+ end
89
90
 
90
- def modularized_extensions(*extensions)
91
- extensions.flatten.compact.map do |extension|
92
- Proc === extension ? Module.new(&extension) : extension
93
- end
91
+ def modularized_extensions(*extensions)
92
+ extensions.flatten.compact.map do |extension|
93
+ Proc === extension ? Module.new(&extension) : extension
94
94
  end
95
+ end
95
96
  end
96
97
  end
97
98
  end
@@ -19,15 +19,16 @@ module MongoMapper
19
19
  @target
20
20
  end
21
21
 
22
- protected
23
- def find_target
24
- return nil if association_class.nil? || proxy_owner[association.foreign_key].nil?
25
- association_class.find_by_id(proxy_owner[association.foreign_key])
26
- end
22
+ protected
27
23
 
28
- def association_class
29
- proxy_owner[association.type_key_name] ? proxy_owner[association.type_key_name].constantize : nil
30
- end
24
+ def find_target
25
+ return nil if association_class.nil? || proxy_owner[association.foreign_key].nil?
26
+ association_class.find_by_id(proxy_owner[association.foreign_key])
27
+ end
28
+
29
+ def association_class
30
+ proxy_owner[association.type_key_name] ? proxy_owner[association.type_key_name].constantize : nil
31
+ end
31
32
  end
32
33
  end
33
34
  end
@@ -34,18 +34,19 @@ module MongoMapper
34
34
  @target.save(options) if @target
35
35
  end
36
36
 
37
- protected
38
- def find_target
39
- return nil if proxy_owner[association.foreign_key].nil?
40
- klass.find_by_id(proxy_owner[association.foreign_key])
41
- end
37
+ protected
42
38
 
43
- def instantiate_target(instantiator, attrs={}, &block)
44
- @target = klass.send(instantiator, attrs, &block)
45
- proxy_owner[association.foreign_key] = @target.id
46
- loaded
47
- @target
48
- end
39
+ def find_target
40
+ return nil if proxy_owner[association.foreign_key].nil?
41
+ klass.find_by_id(proxy_owner[association.foreign_key])
42
+ end
43
+
44
+ def instantiate_target(instantiator, attrs={}, &block)
45
+ @target = klass.send(instantiator, attrs, &block)
46
+ proxy_owner[association.foreign_key] = @target.id
47
+ loaded
48
+ @target
49
+ end
49
50
  end
50
51
  end
51
52
  end
@@ -34,10 +34,10 @@ module MongoMapper
34
34
  @target.each { |doc| doc.persist(options) } if @target
35
35
  end
36
36
 
37
- private
38
- def assign_references(*docs)
39
- docs.each { |doc| doc._parent_document = proxy_owner }
40
- end
37
+ private
38
+ def assign_references(*docs)
39
+ docs.each { |doc| doc._parent_document = proxy_owner }
40
+ end
41
41
  end
42
42
  end
43
43
  end
@@ -99,34 +99,35 @@ module MongoMapper
99
99
  reset
100
100
  end
101
101
 
102
- private
103
- def query(options={})
104
- klass.
105
- query(association.query_options).
106
- amend(options).
107
- amend(criteria)
108
- end
102
+ private
109
103
 
110
- def criteria
111
- {:_id => ids}
112
- end
104
+ def query(options={})
105
+ klass.
106
+ query(association.query_options).
107
+ amend(options).
108
+ amend(criteria)
109
+ end
113
110
 
114
- def scoped_ids(args)
115
- valid = args.flatten.select do |id|
116
- id = ObjectId.to_mongo(id) if klass.using_object_id?
117
- ids.include?(id)
118
- end
119
- valid.empty? ? nil : valid
120
- end
111
+ def criteria
112
+ {:_id => ids}
113
+ end
121
114
 
122
- def find_target
123
- return [] if ids.blank?
124
- all
115
+ def scoped_ids(args)
116
+ valid = args.flatten.select do |id|
117
+ id = ObjectId.to_mongo(id) if klass.using_object_id?
118
+ ids.include?(id)
125
119
  end
120
+ valid.empty? ? nil : valid
121
+ end
126
122
 
127
- def ids
128
- proxy_owner[options[:in]]
129
- end
123
+ def find_target
124
+ return [] if ids.blank?
125
+ all
126
+ end
127
+
128
+ def ids
129
+ proxy_owner[options[:in]]
130
+ end
130
131
  end
131
132
  end
132
133
  end
@@ -3,25 +3,27 @@ module MongoMapper
3
3
  module Plugins
4
4
  module Associations
5
5
  class ManyDocumentsAsProxy < ManyDocumentsProxy
6
- protected
7
- def criteria
8
- {type_key_name => proxy_owner.class.name, id_key_name => proxy_owner.id}
9
- end
6
+ protected
10
7
 
11
- def apply_scope(doc)
12
- ensure_owner_saved
13
- criteria.each { |key, value| doc[key] = value }
14
- doc
15
- end
8
+ def criteria
9
+ {type_key_name => proxy_owner.class.name, id_key_name => proxy_owner.id}
10
+ end
16
11
 
17
- private
18
- def type_key_name
19
- "#{options[:as]}_type"
20
- end
12
+ def apply_scope(doc)
13
+ ensure_owner_saved
14
+ criteria.each { |key, value| doc[key] = value }
15
+ doc
16
+ end
21
17
 
22
- def id_key_name
23
- "#{options[:as]}_id"
24
- end
18
+ private
19
+
20
+ def type_key_name
21
+ "#{options[:as]}_type"
22
+ end
23
+
24
+ def id_key_name
25
+ "#{options[:as]}_id"
26
+ end
25
27
  end
26
28
  end
27
29
  end