mongo_mapper-rails3 0.7.0.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/README.rdoc +8 -37
  2. metadata +16 -284
  3. data/.gitignore +0 -10
  4. data/Gemfile +0 -15
  5. data/LICENSE +0 -20
  6. data/Rakefile +0 -58
  7. data/VERSION +0 -1
  8. data/bin/mmconsole +0 -60
  9. data/lib/mongo_mapper.rb +0 -131
  10. data/lib/mongo_mapper/document.rb +0 -439
  11. data/lib/mongo_mapper/embedded_document.rb +0 -68
  12. data/lib/mongo_mapper/plugins.rb +0 -30
  13. data/lib/mongo_mapper/plugins/associations.rb +0 -106
  14. data/lib/mongo_mapper/plugins/associations/base.rb +0 -123
  15. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +0 -30
  16. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +0 -25
  17. data/lib/mongo_mapper/plugins/associations/collection.rb +0 -21
  18. data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +0 -50
  19. data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +0 -141
  20. data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +0 -28
  21. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +0 -120
  22. data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +0 -31
  23. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +0 -23
  24. data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +0 -13
  25. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +0 -68
  26. data/lib/mongo_mapper/plugins/associations/proxy.rb +0 -119
  27. data/lib/mongo_mapper/plugins/callbacks.rb +0 -87
  28. data/lib/mongo_mapper/plugins/clone.rb +0 -14
  29. data/lib/mongo_mapper/plugins/descendants.rb +0 -17
  30. data/lib/mongo_mapper/plugins/dirty.rb +0 -120
  31. data/lib/mongo_mapper/plugins/equality.rb +0 -24
  32. data/lib/mongo_mapper/plugins/identity_map.rb +0 -124
  33. data/lib/mongo_mapper/plugins/inspect.rb +0 -15
  34. data/lib/mongo_mapper/plugins/keys.rb +0 -310
  35. data/lib/mongo_mapper/plugins/logger.rb +0 -19
  36. data/lib/mongo_mapper/plugins/pagination.rb +0 -26
  37. data/lib/mongo_mapper/plugins/pagination/proxy.rb +0 -72
  38. data/lib/mongo_mapper/plugins/protected.rb +0 -46
  39. data/lib/mongo_mapper/plugins/rails.rb +0 -46
  40. data/lib/mongo_mapper/plugins/serialization.rb +0 -50
  41. data/lib/mongo_mapper/plugins/validations.rb +0 -88
  42. data/lib/mongo_mapper/query.rb +0 -130
  43. data/lib/mongo_mapper/support.rb +0 -217
  44. data/lib/mongo_mapper/support/descendant_appends.rb +0 -46
  45. data/lib/mongo_mapper/support/find.rb +0 -77
  46. data/mongo_mapper-rails3.gemspec +0 -208
  47. data/performance/read_write.rb +0 -52
  48. data/specs.watchr +0 -51
  49. data/test/NOTE_ON_TESTING +0 -1
  50. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +0 -63
  51. data/test/functional/associations/test_belongs_to_proxy.rb +0 -101
  52. data/test/functional/associations/test_in_array_proxy.rb +0 -321
  53. data/test/functional/associations/test_many_documents_as_proxy.rb +0 -229
  54. data/test/functional/associations/test_many_documents_proxy.rb +0 -453
  55. data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +0 -176
  56. data/test/functional/associations/test_many_embedded_proxy.rb +0 -256
  57. data/test/functional/associations/test_many_polymorphic_proxy.rb +0 -302
  58. data/test/functional/associations/test_one_proxy.rb +0 -161
  59. data/test/functional/test_associations.rb +0 -44
  60. data/test/functional/test_binary.rb +0 -27
  61. data/test/functional/test_callbacks.rb +0 -81
  62. data/test/functional/test_dirty.rb +0 -163
  63. data/test/functional/test_document.rb +0 -1244
  64. data/test/functional/test_embedded_document.rb +0 -125
  65. data/test/functional/test_identity_map.rb +0 -508
  66. data/test/functional/test_logger.rb +0 -20
  67. data/test/functional/test_modifiers.rb +0 -252
  68. data/test/functional/test_pagination.rb +0 -93
  69. data/test/functional/test_protected.rb +0 -161
  70. data/test/functional/test_string_id_compatibility.rb +0 -67
  71. data/test/functional/test_validations.rb +0 -329
  72. data/test/models.rb +0 -232
  73. data/test/support/custom_matchers.rb +0 -55
  74. data/test/support/timing.rb +0 -16
  75. data/test/test_helper.rb +0 -59
  76. data/test/unit/associations/test_base.rb +0 -207
  77. data/test/unit/associations/test_proxy.rb +0 -105
  78. data/test/unit/serializers/test_json_serializer.rb +0 -189
  79. data/test/unit/test_descendant_appends.rb +0 -71
  80. data/test/unit/test_document.rb +0 -231
  81. data/test/unit/test_dynamic_finder.rb +0 -123
  82. data/test/unit/test_embedded_document.rb +0 -663
  83. data/test/unit/test_keys.rb +0 -169
  84. data/test/unit/test_lint.rb +0 -8
  85. data/test/unit/test_mongo_mapper.rb +0 -125
  86. data/test/unit/test_pagination.rb +0 -160
  87. data/test/unit/test_plugins.rb +0 -51
  88. data/test/unit/test_query.rb +0 -334
  89. data/test/unit/test_rails.rb +0 -123
  90. data/test/unit/test_rails_compatibility.rb +0 -57
  91. data/test/unit/test_serialization.rb +0 -51
  92. data/test/unit/test_support.rb +0 -362
  93. data/test/unit/test_time_zones.rb +0 -39
  94. data/test/unit/test_validations.rb +0 -557
@@ -1,141 +0,0 @@
1
- module MongoMapper
2
- module Plugins
3
- module Associations
4
- class InArrayProxy < Collection
5
- include Support::Find
6
-
7
- def find(*args)
8
- options = args.extract_options!
9
-
10
- case args.first
11
- when :first
12
- first(options)
13
- when :last
14
- last(options)
15
- when :all
16
- all(options)
17
- else
18
- klass.find(*scoped_ids(args) << scoped_options(options))
19
- end
20
- end
21
-
22
- def find!(*args)
23
- options = args.extract_options!
24
-
25
- case args.first
26
- when :first
27
- first(options)
28
- when :last
29
- last(options)
30
- when :all
31
- all(options)
32
- else
33
- klass.find!(*scoped_ids(args) << scoped_options(options))
34
- end
35
- end
36
-
37
- def paginate(options)
38
- klass.paginate(scoped_options(options))
39
- end
40
-
41
- def all(options={})
42
- klass.all(scoped_options(options))
43
- end
44
-
45
- def first(options={})
46
- klass.first(scoped_options(options))
47
- end
48
-
49
- def last(options={})
50
- klass.last(scoped_options(options))
51
- end
52
-
53
- def count(options={})
54
- options.blank? ? ids.size : klass.count(scoped_options(options))
55
- end
56
-
57
- def destroy_all(options={})
58
- all(options).each do |doc|
59
- ids.delete(doc.id)
60
- doc.destroy
61
- end
62
- reset
63
- end
64
-
65
- def delete_all(options={})
66
- docs = all(options.merge(:select => ['_id']))
67
- docs.each { |doc| ids.delete(doc.id) }
68
- klass.delete(docs.map(&:id))
69
- reset
70
- end
71
-
72
- def nullify
73
- replace([])
74
- reset
75
- end
76
-
77
- def create(attrs={})
78
- doc = klass.create(attrs)
79
- unless doc.new?
80
- ids << doc.id
81
- owner.save
82
- reset
83
- end
84
- doc
85
- end
86
-
87
- def create!(attrs={})
88
- doc = klass.create!(attrs)
89
- unless doc.new?
90
- ids << doc.id
91
- owner.save
92
- reset
93
- end
94
- doc
95
- end
96
-
97
- def <<(*docs)
98
- flatten_deeper(docs).each do |doc|
99
- doc.save if doc.new?
100
- unless ids.include?(doc.id)
101
- ids << doc.id
102
- end
103
- end
104
- reset
105
- end
106
- alias_method :push, :<<
107
- alias_method :concat, :<<
108
-
109
- def replace(docs)
110
- doc_ids = docs.map do |doc|
111
- doc.save if doc.new?
112
- doc.id
113
- end
114
- ids.replace(doc_ids.uniq)
115
- reset
116
- end
117
-
118
- private
119
- def scoped_conditions
120
- {:_id => ids}
121
- end
122
-
123
- def scoped_options(options)
124
- association.query_options.merge(options).merge(scoped_conditions)
125
- end
126
-
127
- def scoped_ids(args)
128
- args.flatten.reject { |id| !ids.include?(id) }
129
- end
130
-
131
- def find_target
132
- ids.blank? ? [] : all
133
- end
134
-
135
- def ids
136
- owner[options[:in]]
137
- end
138
- end
139
- end
140
- end
141
- end
@@ -1,28 +0,0 @@
1
- module MongoMapper
2
- module Plugins
3
- module Associations
4
- class ManyDocumentsAsProxy < ManyDocumentsProxy
5
- protected
6
- def scoped_conditions
7
- {type_key_name => owner.class.name, id_key_name => owner.id}
8
- end
9
-
10
- def apply_scope(doc)
11
- ensure_owner_saved
12
- doc[type_key_name] = owner.class.name
13
- doc[id_key_name] = owner.id
14
- doc
15
- end
16
-
17
- private
18
- def type_key_name
19
- "#{options[:as]}_type"
20
- end
21
-
22
- def id_key_name
23
- "#{options[:as]}_id"
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,120 +0,0 @@
1
- module MongoMapper
2
- module Plugins
3
- module Associations
4
- class ManyDocumentsProxy < Collection
5
- include Support::Find
6
-
7
- def find(*args)
8
- options = args.extract_options!
9
- klass.find(*args << scoped_options(options))
10
- end
11
-
12
- def find!(*args)
13
- options = args.extract_options!
14
- klass.find!(*args << scoped_options(options))
15
- end
16
-
17
- def paginate(options)
18
- klass.paginate(scoped_options(options))
19
- end
20
-
21
- def all(options={})
22
- klass.all(scoped_options(options))
23
- end
24
-
25
- def first(options={})
26
- klass.first(scoped_options(options))
27
- end
28
-
29
- def last(options={})
30
- klass.last(scoped_options(options))
31
- end
32
-
33
- def count(options={})
34
- klass.count(scoped_options(options))
35
- end
36
-
37
- def replace(docs)
38
- load_target
39
- target.map(&:destroy)
40
- docs.each { |doc| apply_scope(doc).save }
41
- reset
42
- end
43
-
44
- def <<(*docs)
45
- ensure_owner_saved
46
- flatten_deeper(docs).each { |doc| apply_scope(doc).save }
47
- reset
48
- end
49
- alias_method :push, :<<
50
- alias_method :concat, :<<
51
-
52
- def build(attrs={})
53
- doc = klass.new(attrs)
54
- apply_scope(doc)
55
- reset
56
- doc
57
- end
58
-
59
- def create(attrs={})
60
- doc = klass.new(attrs)
61
- apply_scope(doc).save
62
- reset
63
- doc
64
- end
65
-
66
- def create!(attrs={})
67
- doc = klass.new(attrs)
68
- apply_scope(doc).save!
69
- reset
70
- doc
71
- end
72
-
73
- def destroy_all(options={})
74
- all(options).map(&:destroy)
75
- reset
76
- end
77
-
78
- def delete_all(options={})
79
- klass.delete_all(options.merge(scoped_conditions))
80
- reset
81
- end
82
-
83
- def nullify
84
- criteria = Query.new(klass, scoped_conditions).criteria
85
- all(criteria).each do |doc|
86
- doc.update_attributes(self.foreign_key => nil)
87
- end
88
- reset
89
- end
90
-
91
- protected
92
- def scoped_conditions
93
- {self.foreign_key => owner.id}
94
- end
95
-
96
- def scoped_options(options)
97
- association.query_options.merge(options).merge(scoped_conditions)
98
- end
99
-
100
- def find_target
101
- all
102
- end
103
-
104
- def ensure_owner_saved
105
- owner.save if owner.new?
106
- end
107
-
108
- def apply_scope(doc)
109
- ensure_owner_saved
110
- doc[foreign_key] = owner.id
111
- doc
112
- end
113
-
114
- def foreign_key
115
- options[:foreign_key] || owner.class.name.underscore.gsub("/", "_") + "_id"
116
- end
117
- end
118
- end
119
- end
120
- end
@@ -1,31 +0,0 @@
1
- module MongoMapper
2
- module Plugins
3
- module Associations
4
- class ManyEmbeddedPolymorphicProxy < EmbeddedCollection
5
- def replace(values)
6
- @_values = values.map do |v|
7
- v.respond_to?(:attributes) ? v.attributes.merge(association.type_key_name => v.class.name) : v
8
- end
9
- reset
10
- end
11
-
12
- protected
13
- def find_target
14
- (@_values || []).map do |hash|
15
- child = polymorphic_class(hash).load(hash)
16
- assign_references(child)
17
- child
18
- end
19
- end
20
-
21
- def polymorphic_class(doc)
22
- if class_name = doc[association.type_key_name]
23
- class_name.constantize
24
- else
25
- klass
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,23 +0,0 @@
1
- module MongoMapper
2
- module Plugins
3
- module Associations
4
- class ManyEmbeddedProxy < EmbeddedCollection
5
- def replace(values)
6
- @_values = values.map do |v|
7
- v.respond_to?(:attributes) ? v.attributes : v
8
- end
9
- reset
10
- end
11
-
12
- private
13
- def find_target
14
- (@_values || []).map do |v|
15
- child = klass.load(v)
16
- assign_references(child)
17
- child
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,13 +0,0 @@
1
- module MongoMapper
2
- module Plugins
3
- module Associations
4
- class ManyPolymorphicProxy < ManyDocumentsProxy
5
- private
6
- def apply_scope(doc)
7
- doc[association.type_key_name] = doc.class.name
8
- super
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,68 +0,0 @@
1
- module MongoMapper
2
- module Plugins
3
- module Associations
4
- class OneProxy < Proxy
5
- undef_method :object_id
6
-
7
- def build(attrs={})
8
- instantiate_target(:new, attrs)
9
- end
10
-
11
- def create(attrs={})
12
- instantiate_target(:create, attrs)
13
- end
14
-
15
- def create!(attrs={})
16
- instantiate_target(:create!, attrs)
17
- end
18
-
19
- def replace(doc)
20
- load_target
21
-
22
- if !target.nil? && target != doc
23
- if options[:dependent] && !target.new?
24
- case options[:dependent]
25
- when :delete
26
- target.delete
27
- when :destroy
28
- target.destroy
29
- when :nullify
30
- target[foreign_key] = nil
31
- target.save
32
- end
33
- end
34
- end
35
-
36
- reset
37
-
38
- unless doc.nil?
39
- owner.save if owner.new?
40
- doc[foreign_key] = owner.id
41
- doc.save if doc.new?
42
- loaded
43
- @target = doc
44
- end
45
- end
46
-
47
- protected
48
- def find_target
49
- target_class.first(association.query_options.merge(foreign_key => owner.id))
50
- end
51
-
52
- def instantiate_target(instantiator, attrs={})
53
- @target = target_class.send(instantiator, attrs.update(foreign_key => owner.id))
54
- loaded
55
- @target
56
- end
57
-
58
- def target_class
59
- @target_class ||= options[:class] || (options[:class_name] || association.name.to_s.camelize).constantize
60
- end
61
-
62
- def foreign_key
63
- options[:foreign_key] || owner.class.name.foreign_key
64
- end
65
- end
66
- end
67
- end
68
- end
@@ -1,119 +0,0 @@
1
- require 'active_support/core_ext/module/delegation'
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
- @target = find_target unless loaded?
101
- loaded
102
- @target
103
- rescue MongoMapper::DocumentNotFound
104
- reset
105
- end
106
-
107
- def find_target
108
- raise NotImplementedError
109
- end
110
-
111
- def flatten_deeper(array)
112
- array.collect do |element|
113
- (element.respond_to?(:flatten) && !element.is_a?(Hash)) ? element.flatten : element
114
- end.flatten
115
- end
116
- end
117
- end
118
- end
119
- end