mongo_doc 0.4.2 → 0.5.5

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 (54) hide show
  1. data/.gitignore +1 -0
  2. data/HISTORY.md +8 -1
  3. data/README.textile +12 -24
  4. data/Rakefile +58 -11
  5. data/VERSION +1 -1
  6. data/features/embed_hash.feature +16 -0
  7. data/features/step_definitions/document_steps.rb +1 -1
  8. data/features/step_definitions/documents.rb +2 -0
  9. data/features/step_definitions/embed_hash_steps.rb +6 -0
  10. data/features/step_definitions/string_casting_steps.rb +2 -1
  11. data/features/support/support.rb +1 -0
  12. data/lib/mongo_doc/associations/collection_proxy.rb +29 -13
  13. data/lib/mongo_doc/associations/document_proxy.rb +14 -5
  14. data/lib/mongo_doc/associations/hash_proxy.rb +20 -16
  15. data/lib/mongo_doc/associations/proxy_base.rb +21 -26
  16. data/lib/mongo_doc/associations.rb +15 -6
  17. data/lib/mongo_doc/attributes.rb +2 -20
  18. data/lib/mongo_doc/collection.rb +1 -1
  19. data/lib/mongo_doc/connection.rb +1 -1
  20. data/lib/mongo_doc/contexts/ids.rb +3 -3
  21. data/lib/mongo_doc/contexts/mongo.rb +1 -1
  22. data/lib/mongo_doc/document.rb +30 -13
  23. data/lib/mongo_doc/ext/binary.rb +2 -2
  24. data/lib/mongo_doc/ext/dbref.rb +2 -2
  25. data/lib/mongo_doc/ext/min_max_keys.rb +13 -0
  26. data/lib/mongo_doc/ext/object.rb +4 -2
  27. data/lib/mongo_doc/ext/object_id.rb +2 -2
  28. data/lib/mongo_doc/ext.rb +1 -0
  29. data/lib/mongo_doc/finders.rb +2 -2
  30. data/lib/mongo_doc/root.rb +26 -0
  31. data/lib/mongo_doc/validations.rb +16 -0
  32. data/lib/mongo_doc.rb +2 -1
  33. data/lib/mongoid/criterion/optional.rb +1 -1
  34. data/mongo_doc.gemspec +29 -17
  35. data/perf/mongo_doc_object.rb +78 -0
  36. data/perf/mongo_document.rb +78 -0
  37. data/perf/ruby_driver.rb +43 -0
  38. data/spec/associations/collection_proxy_spec.rb +29 -6
  39. data/spec/associations/document_proxy_spec.rb +22 -19
  40. data/spec/associations/hash_proxy_spec.rb +17 -4
  41. data/spec/associations/proxy_base_spec.rb +92 -0
  42. data/spec/associations_spec.rb +4 -16
  43. data/spec/bson_spec.rb +1 -1
  44. data/spec/connection_spec.rb +2 -2
  45. data/spec/contexts/ids_spec.rb +2 -2
  46. data/spec/document_spec.rb +31 -22
  47. data/spec/ext_spec.rb +8 -0
  48. data/spec/root_spec.rb +41 -0
  49. data/spec/validations_spec.rb +30 -0
  50. metadata +46 -23
  51. data/lib/mongo_doc/query.rb +0 -7
  52. data/perf/mongo_doc_runner.rb +0 -90
  53. data/perf/ruby_driver_runner.rb +0 -64
  54. data/spec/query_spec.rb +0 -12
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  *.sw?
2
2
  .DS_Store
3
+ .rvmrc
3
4
  coverage
4
5
  rdoc
5
6
  pkg
data/HISTORY.md CHANGED
@@ -1,4 +1,11 @@
1
+ ## 0.5.0 to 0.5.5
2
+
3
+ * update to ruby driver 0.20.1 and the new bson gems
4
+ * require MongoDB 1.4
5
+ * can be used with ActiveSupport 2 or 3
6
+ * Rails3 support with [MongoDoc-Rails](http://github.com/leshill/mongo_doc-rails) thanks to elliotcm
7
+
1
8
  ## 0.4.2
2
9
 
3
- * 'Document#update_attributes' uses $ positional operator when used from within an embed_many association
10
+ * `Document#update_attributes` uses $ positional operator when used from within an embed_many association
4
11
  * Require MongoDB 1.3.4 or greater
data/README.textile CHANGED
@@ -1,37 +1,17 @@
1
1
  h1. MongoDoc
2
2
 
3
- Version: Turbulence (0.4.2) 2010/03/23
4
-
5
- h2. What's New in Turbulence (0.4.2)
6
-
7
- Support for the $ positional operator for in-place array updates. This requires MongoDB version 1.3.4 or higher.
8
-
9
- h2. What's New in Turbulence (0.4.1)
10
-
11
- API changes (@key@ and @has_*@ still supported, will be deprectated soon)
12
-
13
- * @MongoDoc::Document.attr_accessor@ works like the old @key@ macro, and allows two parameters:
14
- ** @:default => 'some default value'@
15
- ** @:type => Date@ used when dealing with values from the web which will be coming in as @String@ values
16
- * Association macros have been renamed
17
- ** @embed@ was @has_one@
18
- ** @embed_many@ was @has_many@
19
- ** @embed_hash@ was @has_hash@
20
-
21
- Indexing suppport
22
-
23
- * @MongoDoc::Document.index@
3
+ Version: Maelstrom (0.5.5) 2010/04/08
24
4
 
25
5
  h2. Notes
26
6
 
27
- * 2010-03-12 Thanks to weather in ATL, cleaned up attr_accessor and switched to embed association macros
7
+ * 2010-03-12 Thanks to weather (in ATL, cleaned up attr_accessor and switched to embed association macros
28
8
  * 2010-03-10 Slides are out of date, use key instead of attr_accessor with MongoDoc::Document (implementation was way too hackish)
29
9
  * 2010-02-23 API is *changing* significantly
30
10
  * 2010-01-23 Tracking MongoDoc with @git@? *READ THIS NOTE*[1]
31
11
 
32
12
  h2. Quick Start
33
13
 
34
- * install MongoDB (at least 1.3.2)
14
+ * install MongoDB (at least 1.4.0)
35
15
  * install the Ruby driver @gem install mongo@
36
16
  * install MongoDoc @gem install mongo_doc@
37
17
  * run an example from this directory @ruby -Ilib examples/simple_object.rb@
@@ -135,10 +115,16 @@ bc. hashrocket_address.update_attributes(:street => '320 First Street North, #71
135
115
 
136
116
  h2. Installation
137
117
 
138
- MongoDoc *requires* mongoDB v1.3.2 or later.
118
+ MongoDoc *requires* mongoDB v1.4.0 or later.
139
119
 
140
120
  bc. sudo gem install mongo_doc
141
121
 
122
+ h2. Rails 3
123
+
124
+ As of version 0.5.0, you can use the mongo_doc-rails gem to add Rails3 support.
125
+
126
+ bc. sudo gem install mongo_doc-rails
127
+
142
128
  h2. Connecting
143
129
 
144
130
  By default, MongoDoc will read its configuration from @./mongodb.yml@. If that file does not exist, it will attempt to connect to a standard MongoDB local server setup and use a database name of @"mongodoc"@.
@@ -186,6 +172,8 @@ h3. Thanks
186
172
 
187
173
  Thanks to Sandro and Durran for some great conversations and some lovely code.
188
174
 
175
+ Thanks to Elliot for pushing me to get Rails 3 support
176
+
189
177
  h2. Note on Patches/Pull Requests
190
178
 
191
179
  * Fork the project.
data/Rakefile CHANGED
@@ -10,12 +10,13 @@ begin
10
10
  gem.homepage = "http://github.com/leshill/mongodoc"
11
11
  gem.authors = ["Les Hill"]
12
12
  gem.add_dependency "activesupport", ">= 2.3.4"
13
- gem.add_dependency "mongo", "= 0.19.1"
14
- gem.add_dependency "mongo_ext", "= 0.19.1"
13
+ gem.add_dependency "mongo", "= 0.20.1"
14
+ gem.add_dependency "bson", "= 0.20.1"
15
+ gem.add_dependency "bson_ext", "= 0.20.1"
15
16
  gem.add_dependency "durran-validatable", "= 2.0.1"
16
17
  gem.add_dependency "leshill-will_paginate", "= 2.3.11"
17
18
  gem.add_development_dependency "rspec", "= 1.3.0"
18
- gem.add_development_dependency "cucumber", "= 0.6.2"
19
+ gem.add_development_dependency "cucumber", ">= 0.6.2"
19
20
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
20
21
  end
21
22
  Jeweler::GemcutterTasks.new
@@ -106,15 +107,22 @@ namespace :bench do
106
107
  desc 'Run benchmark for MongoDoc'
107
108
  task 'mongo_doc' do
108
109
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
109
- require 'perf/mongo_doc_runner'
110
- MongoDocRunner.benchmark
110
+ require 'perf/mongo_document'
111
+ benchmark("MongoDoc saving documents", MongoDocument.new)
112
+ end
113
+
114
+ desc 'Run benchmark for MongoDoc Object'
115
+ task 'mongo_object' do
116
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
117
+ require 'perf/mongo_doc_object'
118
+ benchmark("MongoDoc saving objects", MongoDocObject.new)
111
119
  end
112
120
 
113
121
  desc 'Run profiler for driver'
114
122
  task 'driver' do
115
123
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
116
- require 'perf/ruby_driver_runner'
117
- RubyDriverRunner.benchmark
124
+ require 'perf/ruby_driver'
125
+ benchmark("Ruby driver saving hashes", RubyDriver.new)
118
126
  end
119
127
  end
120
128
 
@@ -122,14 +130,53 @@ namespace :prof do
122
130
  desc 'Run profiler for MongoDoc'
123
131
  task 'mongo_doc' do
124
132
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
125
- require 'perf/mongo_doc_runner'
126
- MongoDocRunner.profile
133
+ require 'perf/mongo_document'
134
+ profile("MongoDoc saving documents", MongoDocument.new)
135
+ end
136
+
137
+ desc 'Run profiler for MongoDoc Object'
138
+ task 'mongo_object' do
139
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
140
+ require 'perf/mongo_doc_object'
141
+ profile("MongoDoc saving objects", MongoDocObject.new)
127
142
  end
128
143
 
129
144
  desc 'Run profiler for driver'
130
145
  task 'driver' do
131
146
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
132
- require 'perf/ruby_driver_runner'
133
- RubyDriverRunner.profile
147
+ require 'perf/ruby_driver'
148
+ profile("Ruby driver saving hashes", RubyDriver.new)
149
+ end
150
+
151
+ def benchmark(what, runner)
152
+ puts "Benchmark: " + what
153
+
154
+ runner.generate(10000)
155
+
156
+ Benchmark.bm do |bm|
157
+ bm.report(what + " writes") do
158
+ runner.writes(10000)
159
+ end
160
+ end
161
+
162
+ Benchmark.bm do |bm|
163
+ bm.report(what + " reads") do
164
+ runner.reads(10000)
165
+ end
166
+ end
167
+ end
168
+
169
+ def profile(what, runner)
170
+ puts "Profiling: " + what
171
+ RubyProf.start
172
+
173
+ runner.generate(1000)
174
+ runner.writes(1000)
175
+ runner.reads(1000)
176
+
177
+ result = RubyProf.stop
178
+ printer = RubyProf::FlatPrinter.new(result)
179
+ printer.print(STDOUT, 0)
134
180
  end
135
181
  end
182
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.5.5
@@ -0,0 +1,16 @@
1
+ Feature: Embed Hash
2
+
3
+ Background:
4
+ Given a class Event
5
+
6
+ Scenario: Creating a new document
7
+ Given an Event document named 'event' :
8
+ | Name | Venue | Date |
9
+ | NoSQL Live | John Hancock Conference Center | 2010-03-11 |
10
+ And an Address document named 'address' :
11
+ | Street | City | State | Zip Code |
12
+ | 320 First Street North | Jacksonville Beach | FL | 32250 |
13
+ And I put the 'address' object on key 'office' of the 'addresses' hash of 'event'
14
+ When I save the document 'event'
15
+ Then the last return value is true
16
+ And the document 'event' roundtrips
@@ -42,7 +42,7 @@ end
42
42
 
43
43
  Given /^I set the id on the document '(.*)' to (.*)$/ do |doc_name, value|
44
44
  doc = instance_variable_get("@#{doc_name}")
45
- doc._id = Mongo::ObjectID.from_string("%024x" % value.to_i(16))
45
+ doc._id = BSON::ObjectID.from_string("%024x" % value.to_i(16))
46
46
  end
47
47
 
48
48
  Given /^'(.+)' has one (.+?) as (.+?) \(identified by '(.+)'\):$/ do |doc_name, class_name, assoc_name, var_name, table|
@@ -35,4 +35,6 @@ class Event
35
35
  attr_accessor :name
36
36
  attr_accessor :venue
37
37
  attr_accessor :date, :type => Date
38
+
39
+ embed_hash :addresses
38
40
  end
@@ -0,0 +1,6 @@
1
+ Given /^I put the '(\w+)' object on key '(\w+)' of the '(\w+)' hash of '(\w+)'$/ do |value_name, key, assoc, doc_name|
2
+ value = instance_variable_get("@#{value_name}")
3
+ doc = instance_variable_get("@#{doc_name}")
4
+ doc.send(assoc)[key] = value
5
+ end
6
+
@@ -14,7 +14,8 @@ def all=(value)
14
14
  @all = value
15
15
  end
16
16
 
17
- Given /^a class Event$/ do
17
+ Given /^a class (.+)$/ do |type_name|
18
+ type_name.constantize.should be_kind_of(Class)
18
19
  end
19
20
 
20
21
  Given /^I create an (.+) '(.+)' with:$/ do |klass_name, object_name, table|
@@ -3,6 +3,7 @@ require 'cucumber'
3
3
  require 'spec/expectations'
4
4
  require 'spec/bson_matchers'
5
5
  require 'mongo_doc'
6
+ require 'active_support/json'
6
7
 
7
8
  MongoDoc::Connection.env = 'cucumber'
8
9
  MongoDoc::Connection.config_path = './features/mongodb.yml'
@@ -24,16 +24,34 @@ module MongoDoc
24
24
 
25
25
  attr_reader :collection
26
26
 
27
- def _root=(root)
28
- @_root = root
27
+ def _modifier_path=(path)
28
+ super
29
29
  collection.each do |item|
30
- item._root = root if is_document?(item)
30
+ item._modifier_path = _modifier_path + '.$' if ProxyBase.is_document?(item)
31
31
  end
32
32
  end
33
33
 
34
+ def _root=(value)
35
+ @_root = value
36
+ collection.each do |item|
37
+ item._root = value if ProxyBase.is_document?(item)
38
+ end
39
+ end
40
+
41
+ %w(_root _selector_path).each do |setter|
42
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
43
+ def #{setter}=(val)
44
+ super
45
+ collection.each do |item|
46
+ item.#{setter} = #{setter} if ProxyBase.is_document?(item)
47
+ end
48
+ end
49
+ RUBY
50
+ end
51
+
34
52
  def initialize(options)
35
- super
36
53
  @collection = []
54
+ super
37
55
  end
38
56
 
39
57
  alias _append <<
@@ -52,7 +70,7 @@ module MongoDoc
52
70
  alias insert []=
53
71
 
54
72
  def build(attrs)
55
- item = assoc_class.new(attrs)
73
+ item = _assoc_class.new(attrs)
56
74
  push(item)
57
75
  end
58
76
 
@@ -82,7 +100,7 @@ module MongoDoc
82
100
 
83
101
  def valid?
84
102
  all? do |child|
85
- if is_document?(child)
103
+ if ProxyBase.is_document?(child)
86
104
  child.valid?
87
105
  else
88
106
  true
@@ -92,13 +110,11 @@ module MongoDoc
92
110
 
93
111
  protected
94
112
 
95
- def annotated_keys(src, attrs, selector = false)
96
- assoc_path = "#{assoc_name}" + (selector ? "" : ".$")
97
- annotated = {}
98
- attrs.each do |(key, value)|
99
- annotated["#{assoc_path}.#{key}"] = value
100
- end
101
- annotated
113
+ def attach_document(doc)
114
+ doc._modifier_path = _modifier_path + '.$'
115
+ doc._selector_path = _selector_path
116
+ doc._root = _root
117
+ _root.send(:register_save_observer, doc)
102
118
  end
103
119
  end
104
120
  end
@@ -7,9 +7,18 @@ module MongoDoc
7
7
 
8
8
  delegate :to_bson, :id, :to => :document
9
9
 
10
- def _root=(root)
11
- @_root = root
12
- document._root = root if is_document?(document)
10
+ %w(_modifier_path _selector_path).each do |setter|
11
+ class_eval(<<-RUBY, __FILE__, __LINE__)
12
+ def #{setter}=(path)
13
+ super
14
+ document.#{setter} = #{setter} if ProxyBase.is_document?(document)
15
+ end
16
+ RUBY
17
+ end
18
+
19
+ def _root=(value)
20
+ @_root = value
21
+ document._root = value if ProxyBase.is_document?(document)
13
22
  end
14
23
 
15
24
  def ==(other)
@@ -21,7 +30,7 @@ module MongoDoc
21
30
  end
22
31
 
23
32
  def build(attrs)
24
- item = assoc_class.new(attrs)
33
+ item = _assoc_class.new(attrs)
25
34
  self.document = item
26
35
  end
27
36
 
@@ -31,7 +40,7 @@ module MongoDoc
31
40
  end
32
41
 
33
42
  def valid?
34
- if is_document?(document)
43
+ if ProxyBase.is_document?(document)
35
44
  document.valid?
36
45
  else
37
46
  true
@@ -21,28 +21,31 @@ module MongoDoc
21
21
 
22
22
  attr_reader :hash
23
23
 
24
- def _root=(root)
25
- @_root = root
26
- hash.each do |key, value|
27
- value._root = root if is_document?(value)
28
- end
24
+ %w(_modifier_path _selector_path).each do |setter|
25
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
26
+ def #{setter}=(path)
27
+ super
28
+ hash.each do |key, doc|
29
+ doc.#{setter} = #{setter} + '.' + key.to_s if ProxyBase.is_document?(doc)
30
+ end
31
+ end
32
+ RUBY
29
33
  end
30
34
 
31
35
  def initialize(options)
32
- super
33
36
  @hash = {}
37
+ super
34
38
  end
35
39
 
36
40
  alias put []=
37
41
  def []=(key, value)
38
42
  raise InvalidEmbeddedHashKey.new("Key name [#{key}] must be a valid element name, see http://www.mongodb.org/display/DOCS/BSON#BSON-noteonelementname") unless valid_key?(key)
39
- attach(value)
40
- put(key, value)
43
+ put(key, attach(key, value))
41
44
  end
42
45
  alias store []=
43
46
 
44
47
  def build(key, attrs)
45
- item = assoc_class.new(attrs)
48
+ item = _assoc_class.new(attrs)
46
49
  store(key, item)
47
50
  end
48
51
 
@@ -71,7 +74,7 @@ module MongoDoc
71
74
 
72
75
  def valid?
73
76
  values.all? do |child|
74
- if is_document?(child)
77
+ if ProxyBase.is_document?(child)
75
78
  child.valid?
76
79
  else
77
80
  true
@@ -81,13 +84,14 @@ module MongoDoc
81
84
 
82
85
  protected
83
86
 
84
- def annotated_keys(src, attrs, selector = false)
85
- assoc_path = "#{assoc_name}.#{index(src)}"
86
- annotated = {}
87
- attrs.each do |(key, value)|
88
- annotated["#{assoc_path}.#{key}"] = value
87
+ def attach(key, value)
88
+ if ProxyBase.is_document?(value)
89
+ proxy = DocumentProxy.new(:path => _selector_path, :assoc_name => key, :root => _root, :parent => self)
90
+ proxy.document = value
91
+ proxy
92
+ else
93
+ value
89
94
  end
90
- annotated
91
95
  end
92
96
 
93
97
  def valid_key?(key)
@@ -3,16 +3,16 @@ module MongoDoc
3
3
  module ProxyBase
4
4
  def self.included(klass)
5
5
  klass.class_eval do
6
- attr_reader :assoc_name, :assoc_class, :_parent, :_root
6
+ attr_reader :_assoc_class, :_assoc_name, :_modifier_path, :_root, :_selector_path
7
7
  end
8
8
  end
9
9
 
10
- def _parent=(parent)
11
- @_parent = parent
12
- end
13
-
14
- def _path_to_root(src, attrs, selector = false)
15
- _parent._path_to_root(src, annotated_keys(src, attrs, selector), selector)
10
+ %w(_modifier_path _selector_path).each do |setter|
11
+ module_eval(<<-RUBY, __FILE__, __LINE__)
12
+ def #{setter}=(path)
13
+ @#{setter} = (path.blank? ? '' : path + '.') + _assoc_name.to_s
14
+ end
15
+ RUBY
16
16
  end
17
17
 
18
18
  def _root=(root)
@@ -20,33 +20,28 @@ module MongoDoc
20
20
  end
21
21
 
22
22
  def initialize(options)
23
- @assoc_name = options[:assoc_name]
24
- @assoc_class = options[:assoc_class]
25
- @_root = options[:root]
26
- @_parent = options[:parent]
23
+ @_assoc_name = options[:assoc_name]
24
+ @_assoc_class = options[:assoc_class]
25
+ self._root = options[:root]
26
+ self._selector_path = self._modifier_path = options[:path]
27
27
  end
28
28
 
29
- def attach(item)
30
- if is_document?(item)
31
- item._parent = self
32
- item._root = _root
33
- _root.send(:register_save_observer, item)
34
- end
35
- item
29
+ def self.is_document?(object)
30
+ object.respond_to?(:_root)
36
31
  end
37
32
 
38
33
  protected
39
34
 
40
- def annotated_keys(src, hash, selector = false)
41
- annotated = {}
42
- hash.each do |(key, value)|
43
- annotated["#{assoc_name}.#{key}"] = value
44
- end
45
- annotated
35
+ def attach(obj)
36
+ attach_document(obj) if ProxyBase.is_document?(obj)
37
+ obj
46
38
  end
47
39
 
48
- def is_document?(object)
49
- object.respond_to?(:_parent)
40
+ def attach_document(doc)
41
+ doc._modifier_path = _modifier_path
42
+ doc._selector_path = _selector_path
43
+ doc._root = _root
44
+ _root.send(:register_save_observer, doc)
50
45
  end
51
46
  end
52
47
  end
@@ -20,7 +20,10 @@ module MongoDoc
20
20
  define_method("#{name}=") do |value|
21
21
  association = instance_variable_get("@#{name}")
22
22
  unless association
23
- association = Associations::DocumentProxy.new(:root => _root || self, :parent => self, :assoc_name => name, :assoc_class => assoc_class || self.class.class_from_name(name))
23
+ association = Associations::DocumentProxy.new(:path => _selector_path,
24
+ :root => _root || self,
25
+ :assoc_name => name,
26
+ :assoc_class => assoc_class || self.class.class_from_name(name))
24
27
  instance_variable_set("@#{name}", association)
25
28
  end
26
29
  association.document = value
@@ -29,7 +32,7 @@ module MongoDoc
29
32
  validates_embedded name, :if => Proc.new { !send(name).nil? }
30
33
  end
31
34
  end
32
- alias :has_one :embed
35
+ alias has_one embed
33
36
 
34
37
  def embed_many(*args)
35
38
  options = args.extract_options!
@@ -43,7 +46,10 @@ module MongoDoc
43
46
  define_method("#{name}") do
44
47
  association = instance_variable_get("@#{name}")
45
48
  unless association
46
- association = Associations::CollectionProxy.new(:root => _root || self, :parent => self, :assoc_name => name, :assoc_class => assoc_class || self.class.class_from_name(name))
49
+ association = Associations::CollectionProxy.new(:path => _selector_path,
50
+ :root => _root || self,
51
+ :assoc_name => name,
52
+ :assoc_class => assoc_class || self.class.class_from_name(name))
47
53
  instance_variable_set("@#{name}", association)
48
54
  end
49
55
  association
@@ -60,7 +66,7 @@ module MongoDoc
60
66
  end
61
67
  end
62
68
  end
63
- alias :has_many :embed_many
69
+ alias has_many embed_many
64
70
 
65
71
  def embed_hash(*args)
66
72
  options = args.extract_options!
@@ -74,7 +80,10 @@ module MongoDoc
74
80
  define_method("#{name}") do
75
81
  association = instance_variable_get("@#{name}")
76
82
  unless association
77
- association = Associations::HashProxy.new(:root => _root || self, :parent => self, :assoc_name => name, :assoc_class => assoc_class || self.class.class_from_name(name))
83
+ association = Associations::HashProxy.new(:path => _selector_path,
84
+ :root => _root || self,
85
+ :assoc_name => name,
86
+ :assoc_class => assoc_class || self.class.class_from_name(name))
78
87
  instance_variable_set("@#{name}", association)
79
88
  end
80
89
  association
@@ -87,7 +96,7 @@ module MongoDoc
87
96
  end
88
97
  end
89
98
  end
90
- alias :has_hash :embed_hash
99
+ alias has_hash embed_hash
91
100
 
92
101
  def class_from_name(name)
93
102
  type_name_with_module(name.to_s.classify).constantize rescue nil
@@ -7,7 +7,6 @@ module MongoDoc
7
7
  class_inheritable_array :_associations
8
8
  self._associations = []
9
9
 
10
- attr_accessor :_parent
11
10
  attr_accessor :_id
12
11
 
13
12
  extend ClassMethods
@@ -28,28 +27,11 @@ module MongoDoc
28
27
  end
29
28
  end
30
29
 
31
- def _root
32
- @_root
33
- end
34
-
35
- def _root=(root)
36
- @_root = root
37
- _associations.each do|a|
38
- association = send(a)
39
- association._root = root if association
40
- end
41
- end
42
-
43
- def _path_to_root(src, attrs, selector = false)
44
- return attrs unless _parent
45
- _parent._path_to_root(self, attrs, selector)
46
- end
47
-
48
30
  module ClassMethods
49
31
 
50
32
  def self.extended(klass)
51
33
  klass.class_eval do
52
- metaclass.alias_method_chain :attr_accessor, :mongo
34
+ singleton_class.alias_method_chain :attr_accessor, :mongo
53
35
  end
54
36
  end
55
37
 
@@ -95,7 +77,7 @@ module MongoDoc
95
77
  end
96
78
  end
97
79
  end
98
- alias :key :attr_accessor_with_mongo
80
+ alias key attr_accessor_with_mongo
99
81
 
100
82
  end
101
83
  end
@@ -50,7 +50,7 @@ module MongoDoc
50
50
  def insert(doc_or_docs, options = {})
51
51
  _collection.insert(doc_or_docs.to_bson, options)
52
52
  end
53
- alias :<< :insert
53
+ alias << insert
54
54
 
55
55
  def save(doc, options = {})
56
56
  _collection.save(doc.to_bson, options)
@@ -82,7 +82,7 @@ module MongoDoc
82
82
  end
83
83
 
84
84
  def verify_server_version(connection)
85
- raise UnsupportedServerVersionError.new('MongoDoc requires at least mongoDB version 1.3.2') unless connection.server_version >= "1.3.4"
85
+ raise UnsupportedServerVersionError.new('MongoDoc requires at least mongoDB version 1.4.0') unless connection.server_version >= "1.4.0"
86
86
  end
87
87
  end
88
88
  end
@@ -18,7 +18,7 @@ module Mongoid
18
18
 
19
19
  protected
20
20
 
21
- # Convert ids from strings to +Mongo::ObjectID+s
21
+ # Convert ids from strings to +BSON::ObjectID+s
22
22
  def strings_to_object_ids(ids)
23
23
  if Array === ids
24
24
  ids.map {|id| string_to_object_id(id) }
@@ -28,10 +28,10 @@ module Mongoid
28
28
 
29
29
  end
30
30
 
31
- # Convert ids from strings to +Mongo::ObjectID+s
31
+ # Convert ids from strings to +BSON::ObjectID+s
32
32
  def string_to_object_id(id)
33
33
  if String === id
34
- ::Mongo::ObjectID.from_string(id)
34
+ ::BSON::ObjectID.from_string(id)
35
35
  else
36
36
  id
37
37
  end