mongo_doc_rails2 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/.document +5 -0
  2. data/.gitignore +8 -0
  3. data/HISTORY.md +11 -0
  4. data/LICENSE +20 -0
  5. data/README.textile +185 -0
  6. data/Rakefile +188 -0
  7. data/TODO +40 -0
  8. data/VERSION +1 -0
  9. data/data/.gitignore +2 -0
  10. data/examples/simple_document.rb +46 -0
  11. data/examples/simple_object.rb +34 -0
  12. data/features/collections.feature +9 -0
  13. data/features/embed_hash.feature +16 -0
  14. data/features/finders.feature +76 -0
  15. data/features/indexes.feature +28 -0
  16. data/features/mongodb.yml +7 -0
  17. data/features/mongodoc_base.feature +128 -0
  18. data/features/new_record.feature +36 -0
  19. data/features/partial_updates.feature +95 -0
  20. data/features/removing_documents.feature +68 -0
  21. data/features/saving_an_object.feature +15 -0
  22. data/features/scopes.feature +66 -0
  23. data/features/step_definitions/collection_steps.rb +17 -0
  24. data/features/step_definitions/document_steps.rb +149 -0
  25. data/features/step_definitions/documents.rb +40 -0
  26. data/features/step_definitions/embed_hash_steps.rb +6 -0
  27. data/features/step_definitions/finder_steps.rb +15 -0
  28. data/features/step_definitions/index_steps.rb +10 -0
  29. data/features/step_definitions/json_steps.rb +9 -0
  30. data/features/step_definitions/object_steps.rb +50 -0
  31. data/features/step_definitions/objects.rb +24 -0
  32. data/features/step_definitions/partial_update_steps.rb +31 -0
  33. data/features/step_definitions/query_steps.rb +66 -0
  34. data/features/step_definitions/removing_documents_steps.rb +14 -0
  35. data/features/step_definitions/scope_steps.rb +18 -0
  36. data/features/step_definitions/string_casting_steps.rb +29 -0
  37. data/features/step_definitions/util_steps.rb +7 -0
  38. data/features/string_casting.feature +10 -0
  39. data/features/support/support.rb +10 -0
  40. data/features/using_criteria.feature +142 -0
  41. data/lib/mongo_doc.rb +12 -0
  42. data/lib/mongo_doc/associations.rb +109 -0
  43. data/lib/mongo_doc/associations/collection_proxy.rb +121 -0
  44. data/lib/mongo_doc/associations/document_proxy.rb +65 -0
  45. data/lib/mongo_doc/associations/hash_proxy.rb +102 -0
  46. data/lib/mongo_doc/associations/proxy_base.rb +48 -0
  47. data/lib/mongo_doc/attributes.rb +84 -0
  48. data/lib/mongo_doc/bson.rb +31 -0
  49. data/lib/mongo_doc/collection.rb +82 -0
  50. data/lib/mongo_doc/connection.rb +88 -0
  51. data/lib/mongo_doc/contexts.rb +31 -0
  52. data/lib/mongo_doc/contexts/ids.rb +41 -0
  53. data/lib/mongo_doc/contexts/mongo.rb +272 -0
  54. data/lib/mongo_doc/criteria.rb +70 -0
  55. data/lib/mongo_doc/cursor.rb +32 -0
  56. data/lib/mongo_doc/document.rb +205 -0
  57. data/lib/mongo_doc/ext.rb +16 -0
  58. data/lib/mongo_doc/ext/array.rb +5 -0
  59. data/lib/mongo_doc/ext/binary.rb +7 -0
  60. data/lib/mongo_doc/ext/boolean_class.rb +17 -0
  61. data/lib/mongo_doc/ext/date.rb +19 -0
  62. data/lib/mongo_doc/ext/date_time.rb +17 -0
  63. data/lib/mongo_doc/ext/dbref.rb +7 -0
  64. data/lib/mongo_doc/ext/hash.rb +7 -0
  65. data/lib/mongo_doc/ext/min_max_keys.rb +13 -0
  66. data/lib/mongo_doc/ext/nil_class.rb +5 -0
  67. data/lib/mongo_doc/ext/numeric.rb +17 -0
  68. data/lib/mongo_doc/ext/object.rb +19 -0
  69. data/lib/mongo_doc/ext/object_id.rb +7 -0
  70. data/lib/mongo_doc/ext/regexp.rb +5 -0
  71. data/lib/mongo_doc/ext/string.rb +5 -0
  72. data/lib/mongo_doc/ext/symbol.rb +5 -0
  73. data/lib/mongo_doc/ext/time.rb +9 -0
  74. data/lib/mongo_doc/finders.rb +38 -0
  75. data/lib/mongo_doc/index.rb +46 -0
  76. data/lib/mongo_doc/matchers.rb +35 -0
  77. data/lib/mongo_doc/root.rb +26 -0
  78. data/lib/mongo_doc/scope.rb +64 -0
  79. data/lib/mongo_doc/validations.rb +12 -0
  80. data/lib/mongo_doc/validations/macros.rb +11 -0
  81. data/lib/mongo_doc/validations/validates_embedded.rb +13 -0
  82. data/lib/mongoid/contexts/enumerable.rb +151 -0
  83. data/lib/mongoid/contexts/paging.rb +42 -0
  84. data/lib/mongoid/criteria.rb +239 -0
  85. data/lib/mongoid/criterion/complex.rb +21 -0
  86. data/lib/mongoid/criterion/exclusion.rb +65 -0
  87. data/lib/mongoid/criterion/inclusion.rb +93 -0
  88. data/lib/mongoid/criterion/optional.rb +136 -0
  89. data/lib/mongoid/extensions/hash/criteria_helpers.rb +20 -0
  90. data/lib/mongoid/extensions/symbol/inflections.rb +36 -0
  91. data/lib/mongoid/matchers/all.rb +11 -0
  92. data/lib/mongoid/matchers/default.rb +26 -0
  93. data/lib/mongoid/matchers/exists.rb +13 -0
  94. data/lib/mongoid/matchers/gt.rb +11 -0
  95. data/lib/mongoid/matchers/gte.rb +11 -0
  96. data/lib/mongoid/matchers/in.rb +11 -0
  97. data/lib/mongoid/matchers/lt.rb +11 -0
  98. data/lib/mongoid/matchers/lte.rb +11 -0
  99. data/lib/mongoid/matchers/ne.rb +11 -0
  100. data/lib/mongoid/matchers/nin.rb +11 -0
  101. data/lib/mongoid/matchers/size.rb +11 -0
  102. data/mongo_doc_rails2.gemspec +237 -0
  103. data/mongod.example.yml +2 -0
  104. data/mongodb.example.yml +14 -0
  105. data/perf/mongo_doc_object.rb +83 -0
  106. data/perf/mongo_document.rb +84 -0
  107. data/perf/ruby_driver.rb +49 -0
  108. data/script/console +8 -0
  109. data/spec/array_including_argument_matcher.rb +62 -0
  110. data/spec/associations/collection_proxy_spec.rb +233 -0
  111. data/spec/associations/document_proxy_spec.rb +45 -0
  112. data/spec/associations/hash_proxy_spec.rb +181 -0
  113. data/spec/associations/proxy_base_spec.rb +92 -0
  114. data/spec/associations_spec.rb +218 -0
  115. data/spec/attributes_accessor_spec.rb +33 -0
  116. data/spec/attributes_spec.rb +145 -0
  117. data/spec/bson_matchers.rb +54 -0
  118. data/spec/bson_spec.rb +196 -0
  119. data/spec/collection_spec.rb +169 -0
  120. data/spec/connection_spec.rb +147 -0
  121. data/spec/contexts/ids_spec.rb +49 -0
  122. data/spec/contexts/mongo_spec.rb +235 -0
  123. data/spec/contexts_spec.rb +56 -0
  124. data/spec/criteria_spec.rb +69 -0
  125. data/spec/cursor_spec.rb +91 -0
  126. data/spec/document_ext.rb +9 -0
  127. data/spec/document_spec.rb +553 -0
  128. data/spec/embedded_save_spec.rb +73 -0
  129. data/spec/ext_spec.rb +89 -0
  130. data/spec/finders_spec.rb +61 -0
  131. data/spec/hash_matchers.rb +27 -0
  132. data/spec/index_spec.rb +79 -0
  133. data/spec/matchers_spec.rb +342 -0
  134. data/spec/mongodb.yml +6 -0
  135. data/spec/mongodb_pairs.yml +8 -0
  136. data/spec/new_record_spec.rb +128 -0
  137. data/spec/root_spec.rb +41 -0
  138. data/spec/scope_spec.rb +79 -0
  139. data/spec/spec.opts +2 -0
  140. data/spec/spec_helper.rb +14 -0
  141. data/spec/validations_spec.rb +30 -0
  142. metadata +346 -0
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,8 @@
1
+ *.sw?
2
+ .DS_Store
3
+ .rvmrc
4
+ coverage
5
+ rdoc
6
+ pkg
7
+ mongod.yml
8
+ nohup.out
@@ -0,0 +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
+
8
+ ## 0.4.2
9
+
10
+ * `Document#update_attributes` uses $ positional operator when used from within an embed_many association
11
+ * Require MongoDB 1.3.4 or greater
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Les Hill
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,185 @@
1
+ h1. MongoDoc
2
+
3
+ Version: Hurricane (0.6.1) 2010/05/10
4
+
5
+ h2. Notes
6
+
7
+ This version of MongoDoc is for Rails v2.3.x[1].
8
+
9
+ h2. Quick Start
10
+
11
+ * install MongoDB (at least 1.4.0)
12
+ * install the Ruby driver @gem install mongo@
13
+ * install MongoDoc @gem install mongo_doc_rails2@
14
+ * run an example from this directory @ruby -Ilib examples/simple_object.rb@
15
+
16
+ h2. Introduction
17
+
18
+ MongoDoc is a simple and easy to use ActiveRecord-like object mapper for "mongoDB":http://www.mongodb.org in Ruby.
19
+
20
+ MongoDoc is _also_ an extension of the "Mongo Ruby Driver":http://github.com/mongodb/mongo-ruby-driver making it a snap to get Ruby in and out of mongoDB.
21
+
22
+ MongoDoc is *not* ActiveRecord for mongoDB. We do not have callbacks, nor do we have dynamic finders. We do have associations, named scopes, and other features.
23
+
24
+ MongoDoc *is* simple, easy-to-use, and fast. This version works with Rails 2.3.x.
25
+
26
+ MongoDoc is designed to work with document data, if you are looking to map relational data in mongoDB, you will have to look elsewhere.
27
+
28
+ h2. Ruby objects in mongoDB
29
+
30
+ Lets just get right into it and save some Ruby objects in mongoDB!
31
+
32
+ bc.. class Contact
33
+ attr_accessor :name, :addresses, :interests
34
+ end
35
+
36
+ class Address
37
+ attr_accessor :street, :city, :state, :zip, :phone_number
38
+ end
39
+
40
+ p. With MongoDoc, instead of saving JSON[2], we can save an object directly:
41
+
42
+ bc.. contact = Contact.new
43
+ contact.name = 'Hashrocket'
44
+ contact.interests = ['ruby', 'rails', 'agile']
45
+
46
+ address = Address.new
47
+ address.street = '320 First Street North, #712'
48
+ address.city = 'Jacksonville Beach'
49
+ address.state = 'FL'
50
+ address.zip = '32250'
51
+ address.phone_number = '877 885 8846'
52
+ contact.addresses = [address]
53
+
54
+ collection.save(contact)
55
+
56
+ p. We can query using the powerful mongoDB query syntax, and have it return Ruby objects:
57
+
58
+ bc.. in_fl = collection.where('addresses.state' => 'FL')
59
+ in_fl_hashrocket = in_fl.where('name' => /rocket/)
60
+ puts in_fl_hashrocket.first.addresses.first.phone_number
61
+
62
+ p. Take a look in the examples directory for more code.
63
+
64
+ h2. Mapping Documents
65
+
66
+ MongoDoc provides ActiveRecord-like persistence, associations, named scopes, and validations (from "Validatable":http://github.com/durran/validatable) as well as a mongoDB query language (from "Mongoid":http://mongoid.org/home). MongoDoc also plays nicely with Rails.
67
+
68
+ @MongoDoc::Document@ provides all these features as a mixin. A @MongoDoc::Document@ can either be a top-level mongoDB document, or an embedded document contained within a top-level document. Top-level documents are stored in collections named after their class: @Contact@ objects are stored in the 'contacts' collection (much like ActiveRecord).
69
+
70
+ Lets define a @Contact@ document with an @Address@ embedded document:
71
+
72
+ bc.. class Address
73
+ include MongoDoc::Document
74
+
75
+ attr_accessor :street
76
+ attr_accessor :city
77
+ attr_accessor :state
78
+ attr_accessor :zip_code
79
+ attr_accessor :phone_number
80
+ end
81
+
82
+ class Contact
83
+ include MongoDoc::Document
84
+
85
+ attr_accessor :name
86
+ attr_accessor :interests
87
+ embed_many :addresses
88
+
89
+ scope :in_state, lambda {|state| where('addresses.state' => state)}
90
+ end
91
+
92
+ p. Since a mongoDB document has no fixed schema, we define the composition of a document directly in our classes. We can also specify associations using @embed@, @embed_many@, and @embed_hash@ (similar to ActiveRecord's @has_one@ and @has_many@.
93
+
94
+ Building and saving a document is easy:
95
+
96
+ bc.. contact = Contact.new(:name => 'Hashrocket', :interests => ['ruby', 'rails', 'agile'])
97
+ contact.addresses << Address.new(:street => '320 1st Street North, #712',
98
+ :city => 'Jacksonville Beach',
99
+ :state => 'FL',
100
+ :zip_code => '32250',
101
+ :phone_number => '877 885 8846')
102
+ contact.save
103
+
104
+ p. Now that we have some data, we can query using our named scope:
105
+
106
+ bc.. hashrocket_in_fl = Contact.in_state('FL').where(:name => /rocket/)
107
+ hashrocket_address = hashrocket_in_fl.first.addresses.first
108
+
109
+ p. And we can even perform partial updates:
110
+
111
+ bc. hashrocket_address.update_attributes(:street => '320 First Street North, #712')
112
+
113
+ h2. Installation
114
+
115
+ MongoDoc *requires* mongoDB v1.4.0 or later.
116
+
117
+ bc. gem install mongo_doc_rails2
118
+
119
+ h2. Connecting
120
+
121
+ 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"@.
122
+
123
+ h3. With Rails
124
+
125
+ If you are using Rails, MongoDoc will look for its configuration in @config/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 @#{Rails.root.basename}_#{Rails.env}@.
126
+
127
+ h3. Database configuration file
128
+
129
+ The file is similar to the Rails database.yml file, with environment definitions containing the database configuration attributes. For example:
130
+
131
+ bc. development:
132
+ name: development
133
+ host: localhost
134
+ port: 27017
135
+ options:
136
+ auto_reconnect: true
137
+ test:
138
+ name: test
139
+ host: localhost
140
+ port: 27017
141
+ options:
142
+ auto_reconnect: true
143
+
144
+ If you are not using Rails, the default environment is @development@ and you can set the current environment in your code:
145
+
146
+ bc. MongoDoc::Connection.env = 'test'
147
+
148
+ You can also change the location of the configuration file:
149
+
150
+ bc. MongoDoc::Connection.config_path = './config/mongodb.yml'
151
+
152
+ h3. Programmatically setting the database connection information
153
+
154
+ Finally, if you do not want to use the database configuration file, you can also set the database name, host, port, options, and strict values directly; for example, to set the database name to @stats@:
155
+
156
+ bc. MongoDoc::Connection.name = 'stats'
157
+
158
+ h2. Credits
159
+
160
+ Les Hill, leshill on github
161
+
162
+ h3. Thanks
163
+
164
+ Thanks to Sandro and Durran for some great conversations and some lovely code.
165
+
166
+ Thanks to Elliot for pushing me to get Rails 3 support
167
+
168
+ h2. Note on Patches/Pull Requests
169
+
170
+ * Fork the project.
171
+ * Make your feature addition or bug fix.
172
+ * Add tests for it. This is important so I don't break it in a
173
+ future version unintentionally.
174
+ * Commit, do not mess with rakefile, version, or history.
175
+ (if you want to have your own version, that is fine but
176
+ bump version in a commit by itself I can ignore when I pull)
177
+ * Send me a pull request. Bonus points for topic branches.
178
+
179
+ h2. Copyright
180
+
181
+ Copyright (c) 2009 - 2010 Les Hill. See LICENSE for details.
182
+
183
+ fn1. If you are using Rails 3.x you need to be using the @mongo_doc@ gem from the master branch on "github":http://github.com/leshill/mongodoc .
184
+
185
+ fn2. The Ruby driver exposes an API that understands JSON.
@@ -0,0 +1,188 @@
1
+ require 'rake'
2
+
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |gem|
6
+ gem.name = "mongo_doc_rails2"
7
+ gem.summary = %Q{ODM for MongoDB - for Rails 2.3.x}
8
+ gem.description = %Q{ODM for MongoDB - for Rails 2.3.x}
9
+ gem.email = "leshill@gmail.com"
10
+ gem.homepage = "http://github.com/leshill/mongodoc"
11
+ gem.authors = ["Les Hill"]
12
+ gem.add_dependency "activesupport", ">= 2.3.4"
13
+ gem.add_dependency "mongo", "= 1.0.1"
14
+ gem.add_dependency "bson", "= 1.0.1"
15
+ gem.add_dependency "bson_ext", "= 1.0.1"
16
+ gem.add_dependency "durran-validatable", "= 2.0.1"
17
+ gem.add_dependency "leshill-will_paginate", "= 2.3.11"
18
+ gem.add_development_dependency "rspec", "= 1.3.0"
19
+ gem.add_development_dependency "cucumber", ">= 0.6.2"
20
+ end
21
+ Jeweler::GemcutterTasks.new
22
+ rescue LoadError
23
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
24
+ end
25
+
26
+ require 'cucumber/rake/task'
27
+ Cucumber::Rake::Task.new(:features) do |t|
28
+ t.cucumber_opts = "--format pretty --tag ~@wip"
29
+ end
30
+
31
+ namespace :cucumber do
32
+ Cucumber::Rake::Task.new(:wip) do |t|
33
+ t.cucumber_opts = "--format pretty --tag @wip"
34
+ end
35
+ end
36
+
37
+ require 'spec/rake/spectask'
38
+ Spec::Rake::SpecTask.new(:spec) do |spec|
39
+ spec.spec_opts = ['--options', "#{File.expand_path(File.dirname(__FILE__))}/spec/spec.opts"]
40
+ spec.libs << 'lib' << 'spec'
41
+ spec.spec_files = FileList['spec/**/*_spec.rb']
42
+ end
43
+
44
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
45
+ spec.spec_opts = ['--options', "#{File.expand_path(File.dirname(__FILE__))}/spec/spec.opts"]
46
+ spec.libs << 'lib' << 'spec'
47
+ spec.pattern = 'spec/**/*_spec.rb'
48
+ spec.rcov = true
49
+ end
50
+
51
+ task :spec => :check_dependencies
52
+
53
+ task :default => :spec
54
+
55
+ require 'rake/rdoctask'
56
+ Rake::RDocTask.new do |rdoc|
57
+ if File.exist?('VERSION')
58
+ version = File.read('VERSION')
59
+ else
60
+ version = ""
61
+ end
62
+
63
+ rdoc.rdoc_dir = 'rdoc'
64
+ rdoc.title = "MongoDoc #{version}"
65
+ rdoc.rdoc_files.include('README*')
66
+ rdoc.rdoc_files.include('lib/**/*.rb')
67
+ end
68
+
69
+ namespace :mongo do
70
+ desc 'Start mongod'
71
+ task :start do
72
+ default_config = { "dbpath" => "/data/db" }
73
+ config = begin
74
+ YAML.load_file(File.join(File.dirname(__FILE__), 'mongod.yml'))
75
+ rescue Exception => e
76
+ {}
77
+ end
78
+ config = default_config.merge(config)
79
+ sh("nohup #{config['mongod'] || 'mongod'} --dbpath #{config['dbpath']} &")
80
+ puts "\n"
81
+ end
82
+ end
83
+
84
+ namespace :mongoid do
85
+ desc 'Sync criteria from Mongoid'
86
+ task :sync do
87
+ require 'pathname'
88
+
89
+ src_dir = Pathname.new('../durran-mongoid/lib/mongoid')
90
+ dest_dir = Pathname.new('lib/mongoid')
91
+ dest_dir.mkpath
92
+ %w(criteria.rb contexts/paging.rb contexts/enumerable.rb criterion extensions/symbol/inflections.rb extensions/hash/criteria_helpers.rb matchers).each do |f|
93
+ src = src_dir + f
94
+ if src.directory?
95
+ FileUtils.cp_r(src, dest_dir)
96
+ else
97
+ dest = dest_dir + f
98
+ dest.dirname.mkpath
99
+ FileUtils.cp(src, dest)
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+ namespace :bench do
106
+ desc 'Run benchmark for MongoDoc'
107
+ task 'mongo_doc' do
108
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
109
+ require 'perf/mongo_document'
110
+ benchmark("MongoDoc saving documents", MongoDocument.new)
111
+ end
112
+
113
+ desc 'Run benchmark for MongoDoc Object'
114
+ task 'mongo_object' do
115
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
116
+ require 'perf/mongo_doc_object'
117
+ benchmark("MongoDoc saving objects", MongoDocObject.new)
118
+ end
119
+
120
+ desc 'Run profiler for driver'
121
+ task 'driver' do
122
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
123
+ require 'perf/ruby_driver'
124
+ benchmark("Ruby driver saving hashes", RubyDriver.new)
125
+ end
126
+ end
127
+
128
+ namespace :prof do
129
+ desc 'Run profiler for MongoDoc'
130
+ task 'mongo_doc' do
131
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
132
+ require 'perf/mongo_document'
133
+ profile("MongoDoc saving documents", MongoDocument.new)
134
+ end
135
+
136
+ desc 'Run profiler for MongoDoc Object'
137
+ task 'mongo_object' do
138
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
139
+ require 'perf/mongo_doc_object'
140
+ profile("MongoDoc saving objects", MongoDocObject.new)
141
+ end
142
+
143
+ desc 'Run profiler for driver'
144
+ task 'driver' do
145
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
146
+ require 'perf/ruby_driver'
147
+ profile("Ruby driver saving hashes", RubyDriver.new)
148
+ end
149
+
150
+ def benchmark(what, runner)
151
+ puts "Benchmark: " + what
152
+
153
+ runner.generate(10000)
154
+
155
+ Benchmark.bm do |bm|
156
+ bm.report(what + " writes") do
157
+ runner.writes(10000)
158
+ end
159
+ end
160
+
161
+ Benchmark.bm do |bm|
162
+ bm.report(what + " reads") do
163
+ runner.reads(10000)
164
+ end
165
+ end
166
+
167
+ Benchmark.bm do |bm|
168
+ bm.report(what + " query") do
169
+ runner.query_all
170
+ end
171
+ end
172
+ end
173
+
174
+ def profile(what, runner)
175
+ puts "Profiling: " + what
176
+ RubyProf.start
177
+
178
+ runner.generate(1000)
179
+ runner.writes(1000)
180
+ runner.reads(1000)
181
+ runner.query_all
182
+
183
+ result = RubyProf.stop
184
+ printer = RubyProf::FlatPrinter.new(result)
185
+ printer.print(STDOUT, 0)
186
+ end
187
+ end
188
+
data/TODO ADDED
@@ -0,0 +1,40 @@
1
+ As of 2010-03-06
2
+
3
+ Associations
4
+ ------------
5
+
6
+ Pull associations out of attributes and refactor
7
+
8
+ Criteria
9
+ --------
10
+
11
+ Make critieria module; include into CriteriaProxy, Association?
12
+ page, per_page, paginate shuould be wrapped or not?
13
+
14
+ Contexts
15
+ --------
16
+
17
+ Extract Mongo context as module, Document#collection => klass.collection Collection#collection => klass
18
+
19
+ Documentation
20
+ -------------
21
+
22
+ How to get started with Rails
23
+
24
+ Dynamic Attributes
25
+ ------------------
26
+
27
+ Document#[] => reads attribute
28
+ Document#[]= => writes attribute
29
+ Document#dynamic_attributes => key, value for each dynamic attribute
30
+ Document#dynamic_attribute_names => list of dynamic attribute names
31
+
32
+ Validations
33
+ -----------
34
+
35
+ validates_hash_keys :has_hash_name, :in => [array of names]
36
+
37
+
38
+ Q
39
+ -
40
+ What is Criteria#ids