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,68 +0,0 @@
1
- module MongoMapper
2
- module EmbeddedDocument
3
- extend Support::DescendantAppends
4
- extend ActiveSupport::Concern
5
- included do
6
- extend Plugins
7
-
8
- plugin Plugins::Associations
9
- plugin Plugins::Clone
10
- plugin Plugins::Descendants
11
- plugin Plugins::Equality
12
- plugin Plugins::Inspect
13
- plugin Plugins::Keys
14
- plugin Plugins::Logger
15
- plugin Plugins::Protected
16
- plugin Plugins::Rails
17
- plugin Plugins::Serialization
18
- plugin Plugins::Validations
19
-
20
- attr_accessor :_root_document, :_parent_document
21
- end
22
-
23
- module ClassMethods
24
- def embeddable?
25
- true
26
- end
27
-
28
- def embedded_in(owner_name)
29
- define_method(owner_name) { _parent_document }
30
- end
31
- end
32
-
33
- module InstanceMethods
34
- def initialize(attrs={}, from_database=false)
35
- unless attrs.nil?
36
- provided_keys = attrs.keys.map { |k| k.to_s }
37
- unless provided_keys.include?('_id') || provided_keys.include?('id')
38
- write_key :_id, Mongo::ObjectID.new
39
- end
40
- end
41
-
42
- assign_type_if_present
43
-
44
- if from_database
45
- @new = false
46
- self.attributes = attrs
47
- else
48
- @new = true
49
- assign(attrs)
50
- end
51
- end
52
-
53
- def save(options={})
54
- if result = _root_document.try(:save, options)
55
- @new = false
56
- end
57
- result
58
- end
59
-
60
- def save!(options={})
61
- if result = _root_document.try(:save!, options)
62
- @new = false
63
- end
64
- result
65
- end
66
- end # InstanceMethods
67
- end # EmbeddedDocument
68
- end # MongoMapper
@@ -1,30 +0,0 @@
1
- module MongoMapper
2
- module Plugins
3
- def plugins
4
- @plugins ||= []
5
- end
6
-
7
- def plugin(mod)
8
- include mod
9
- mod.configure(self) if mod.respond_to?(:configure)
10
- plugins << mod
11
- end
12
-
13
- autoload :Callbacks, 'mongo_mapper/plugins/callbacks'
14
- autoload :Clone, 'mongo_mapper/plugins/clone'
15
- autoload :Descendants, 'mongo_mapper/plugins/descendants'
16
- autoload :Dirty, 'mongo_mapper/plugins/dirty'
17
- autoload :Equality, 'mongo_mapper/plugins/equality'
18
- autoload :IdentityMap, 'mongo_mapper/plugins/identity_map'
19
- autoload :Inspect, 'mongo_mapper/plugins/inspect'
20
- autoload :Keys, 'mongo_mapper/plugins/keys'
21
- autoload :Logger, 'mongo_mapper/plugins/logger'
22
- autoload :Protected, 'mongo_mapper/plugins/protected'
23
- autoload :Rails, 'mongo_mapper/plugins/rails'
24
- autoload :Serialization, 'mongo_mapper/plugins/serialization'
25
- autoload :Validations, 'mongo_mapper/plugins/validations'
26
- end
27
- end
28
-
29
- require 'mongo_mapper/plugins/associations'
30
- require 'mongo_mapper/plugins/pagination'
@@ -1,106 +0,0 @@
1
- module MongoMapper
2
- module Plugins
3
- module Associations
4
- extend ActiveSupport::Concern
5
- module ClassMethods
6
- def belongs_to(association_id, options={}, &extension)
7
- create_association(:belongs_to, association_id, options, &extension)
8
- end
9
-
10
- def many(association_id, options={}, &extension)
11
- create_association(:many, association_id, options, &extension)
12
- end
13
-
14
- def one(association_id, options={}, &extension)
15
- create_association(:one, association_id, options, &extension)
16
- end
17
-
18
- def associations
19
- @associations ||= HashWithIndifferentAccess.new
20
- end
21
-
22
- def associations=(hash)
23
- @associations = hash
24
- end
25
-
26
- def inherited(subclass)
27
- subclass.associations = associations.dup
28
- super
29
- end
30
-
31
- private
32
- def create_association(type, name, options, &extension)
33
- association = Associations::Base.new(type, name, options, &extension)
34
- associations[association.name] = association
35
-
36
- define_method(association.name) do
37
- get_proxy(association)
38
- end
39
-
40
- define_method("#{association.name}=") do |value|
41
- get_proxy(association).replace(value)
42
- value
43
- end
44
-
45
- if association.one? || association.belongs_to?
46
- define_method("#{association.name}?") do
47
- get_proxy(association).present?
48
- end
49
- end
50
-
51
- if association.options[:dependent] && association.many? && !association.embeddable?
52
- after_destroy do |doc|
53
- case association.options[:dependent]
54
- when :destroy
55
- doc.get_proxy(association).destroy_all
56
- when :delete_all
57
- doc.get_proxy(association).delete_all
58
- when :nullify
59
- doc.get_proxy(association).nullify
60
- end
61
- end
62
- end
63
- end
64
- end
65
-
66
- module InstanceMethods
67
- def associations
68
- self.class.associations
69
- end
70
-
71
- # @api private?
72
- def embedded_associations
73
- associations.select do |name, association|
74
- association.embeddable?
75
- end.map do |name, association|
76
- association
77
- end
78
- end
79
-
80
- def get_proxy(association)
81
- unless proxy = self.instance_variable_get(association.ivar)
82
- proxy = association.proxy_class.new(self, association)
83
- self.instance_variable_set(association.ivar, proxy)
84
- end
85
-
86
- proxy
87
- end
88
- end
89
-
90
- autoload :Base, 'mongo_mapper/plugins/associations/base'
91
- autoload :Collection, 'mongo_mapper/plugins/associations/collection'
92
- autoload :EmbeddedCollection, 'mongo_mapper/plugins/associations/embedded_collection'
93
- autoload :ManyDocumentsProxy, 'mongo_mapper/plugins/associations/many_documents_proxy'
94
- autoload :BelongsToProxy, 'mongo_mapper/plugins/associations/belongs_to_proxy'
95
- autoload :BelongsToPolymorphicProxy, 'mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy'
96
- autoload :ManyPolymorphicProxy, 'mongo_mapper/plugins/associations/many_polymorphic_proxy'
97
- autoload :ManyEmbeddedProxy, 'mongo_mapper/plugins/associations/many_embedded_proxy'
98
- autoload :ManyEmbeddedPolymorphicProxy, 'mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy'
99
- autoload :ManyDocumentsAsProxy, 'mongo_mapper/plugins/associations/many_documents_as_proxy'
100
- autoload :OneProxy, 'mongo_mapper/plugins/associations/one_proxy'
101
- autoload :InArrayProxy, 'mongo_mapper/plugins/associations/in_array_proxy'
102
- end
103
- end
104
- end
105
-
106
- require 'mongo_mapper/plugins/associations/proxy'
@@ -1,123 +0,0 @@
1
- module MongoMapper
2
- module Plugins
3
- module Associations
4
- class Base
5
- attr_reader :type, :name, :options, :query_options
6
-
7
- # Options that should not be considered MongoDB query options/criteria
8
- AssociationOptions = [:as, :class, :class_name, :dependent, :extend, :foreign_key, :in, :polymorphic]
9
-
10
- def initialize(type, name, options={}, &extension)
11
- @type, @name, @options, @query_options, @original_options = type, name, {}, {}, options
12
- options.symbolize_keys!
13
- options[:extend] = modularized_extensions(extension, options[:extend])
14
- separate_options_and_conditions
15
- end
16
-
17
- def class_name
18
- return @class_name if defined?(@class_name)
19
-
20
- @class_name =
21
- if cn = options[:class_name]
22
- cn
23
- elsif many?
24
- name.to_s.singularize.camelize
25
- else
26
- name.to_s.camelize
27
- end
28
- end
29
-
30
- def klass
31
- @klass ||= options[:class] || class_name.constantize
32
- end
33
-
34
- def many?
35
- @type == :many
36
- end
37
-
38
- def belongs_to?
39
- @type == :belongs_to
40
- end
41
-
42
- def one?
43
- @type == :one
44
- end
45
-
46
- def polymorphic?
47
- !!@options[:polymorphic]
48
- end
49
-
50
- def as?
51
- !!@options[:as]
52
- end
53
-
54
- def in_array?
55
- !!@options[:in]
56
- end
57
-
58
- def embeddable?
59
- many? && klass.embeddable?
60
- end
61
-
62
- def type_key_name
63
- many? ? '_type' : "#{as}_type"
64
- end
65
-
66
- def as
67
- @options[:as] || self.name
68
- end
69
-
70
- def foreign_key
71
- @options[:foreign_key] || "#{name}_id"
72
- end
73
-
74
- def ivar
75
- @ivar ||= "@_#{name}"
76
- end
77
-
78
- # hate this, need to revisit
79
- def proxy_class
80
- return @proxy_class if defined?(@proxy_class)
81
-
82
- @proxy_class =
83
- if many?
84
- if klass.embeddable?
85
- polymorphic? ? ManyEmbeddedPolymorphicProxy : ManyEmbeddedProxy
86
- else
87
- if polymorphic?
88
- ManyPolymorphicProxy
89
- elsif as?
90
- ManyDocumentsAsProxy
91
- elsif in_array?
92
- InArrayProxy
93
- else
94
- ManyDocumentsProxy
95
- end
96
- end
97
- elsif one?
98
- OneProxy
99
- else
100
- polymorphic? ? BelongsToPolymorphicProxy : BelongsToProxy
101
- end
102
- end
103
-
104
- private
105
- def separate_options_and_conditions
106
- @original_options.each_pair do |key, value|
107
- if AssociationOptions.include?(key)
108
- @options[key] = value
109
- else
110
- @query_options[key] = value
111
- end
112
- end
113
- end
114
-
115
- def modularized_extensions(*extensions)
116
- extensions.flatten.compact.map do |extension|
117
- Proc === extension ? Module.new(&extension) : extension
118
- end
119
- end
120
- end
121
- end
122
- end
123
- end
@@ -1,30 +0,0 @@
1
- module MongoMapper
2
- module Plugins
3
- module Associations
4
- class BelongsToPolymorphicProxy < Proxy
5
- undef_method :object_id
6
-
7
- def replace(doc)
8
- if doc
9
- doc.save if doc.new?
10
- id, type = doc.id, doc.class.name
11
- end
12
-
13
- owner[association.foreign_key] = id
14
- owner[association.type_key_name] = type
15
- reset
16
- end
17
-
18
- protected
19
- def find_target
20
- return nil if association_class.nil? || owner[association.foreign_key].nil?
21
- association_class.find_by_id(owner[association.foreign_key])
22
- end
23
-
24
- def association_class
25
- proxy_owner[association.type_key_name] ? proxy_owner[association.type_key_name].constantize : nil
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,25 +0,0 @@
1
- module MongoMapper
2
- module Plugins
3
- module Associations
4
- class BelongsToProxy < Proxy
5
- undef_method :object_id
6
-
7
- def replace(doc)
8
- if doc
9
- doc.save if doc.new?
10
- id = doc.id
11
- end
12
-
13
- owner[association.foreign_key] = id
14
- reset
15
- end
16
-
17
- protected
18
- def find_target
19
- return nil if owner[association.foreign_key].nil?
20
- klass.find_by_id(owner[association.foreign_key])
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,21 +0,0 @@
1
- module MongoMapper
2
- module Plugins
3
- module Associations
4
- class Collection < Proxy
5
- def to_ary
6
- load_target
7
- if target.is_a?(Array)
8
- target.to_ary
9
- else
10
- Array(target)
11
- end
12
- end
13
-
14
- def reset
15
- super
16
- target = []
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,50 +0,0 @@
1
- module MongoMapper
2
- module Plugins
3
- module Associations
4
- class EmbeddedCollection < Collection
5
- def build(attributes={})
6
- doc = klass.new(attributes)
7
- assign_references(doc)
8
- self << doc
9
- doc
10
- end
11
-
12
- def find(id)
13
- load_target
14
- target.detect { |item| item.id.to_s == id || item.id == id }
15
- end
16
-
17
- def count
18
- load_target
19
- target.size
20
- end
21
-
22
- def <<(*docs)
23
- load_target
24
- docs.each do |doc|
25
- assign_references(doc)
26
- target << doc
27
- end
28
- end
29
- alias_method :push, :<<
30
- alias_method :concat, :<<
31
-
32
- private
33
- def _root_document
34
- if owner.respond_to?(:_root_document)
35
- owner._root_document
36
- else
37
- owner
38
- end
39
- end
40
-
41
- def assign_references(*docs)
42
- docs.each do |doc|
43
- doc._root_document = _root_document
44
- doc._parent_document = owner
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end