mongo 0.1.0 → 0.15
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.
- data/README.rdoc +268 -71
- data/Rakefile +27 -62
- data/bin/bson_benchmark.rb +59 -0
- data/bin/mongo_console +3 -3
- data/bin/run_test_script +19 -0
- data/bin/standard_benchmark +109 -0
- data/examples/admin.rb +41 -0
- data/examples/benchmarks.rb +42 -0
- data/examples/blog.rb +76 -0
- data/examples/capped.rb +23 -0
- data/examples/cursor.rb +47 -0
- data/examples/gridfs.rb +87 -0
- data/examples/index_test.rb +125 -0
- data/examples/info.rb +30 -0
- data/examples/queries.rb +69 -0
- data/examples/simple.rb +23 -0
- data/examples/strict.rb +34 -0
- data/examples/types.rb +35 -0
- data/lib/mongo.rb +9 -2
- data/lib/mongo/admin.rb +65 -68
- data/lib/mongo/collection.rb +379 -117
- data/lib/mongo/connection.rb +151 -0
- data/lib/mongo/cursor.rb +271 -216
- data/lib/mongo/db.rb +500 -315
- data/lib/mongo/errors.rb +26 -0
- data/lib/mongo/gridfs.rb +16 -0
- data/lib/mongo/gridfs/chunk.rb +92 -0
- data/lib/mongo/gridfs/grid_store.rb +464 -0
- data/lib/mongo/message.rb +16 -0
- data/lib/mongo/message/get_more_message.rb +24 -13
- data/lib/mongo/message/insert_message.rb +29 -11
- data/lib/mongo/message/kill_cursors_message.rb +23 -12
- data/lib/mongo/message/message.rb +74 -62
- data/lib/mongo/message/message_header.rb +35 -24
- data/lib/mongo/message/msg_message.rb +21 -9
- data/lib/mongo/message/opcodes.rb +26 -15
- data/lib/mongo/message/query_message.rb +63 -43
- data/lib/mongo/message/remove_message.rb +29 -12
- data/lib/mongo/message/update_message.rb +30 -13
- data/lib/mongo/query.rb +97 -89
- data/lib/mongo/types/binary.rb +25 -21
- data/lib/mongo/types/code.rb +30 -0
- data/lib/mongo/types/dbref.rb +19 -23
- data/lib/mongo/types/objectid.rb +130 -116
- data/lib/mongo/types/regexp_of_holding.rb +27 -31
- data/lib/mongo/util/bson.rb +273 -160
- data/lib/mongo/util/byte_buffer.rb +32 -28
- data/lib/mongo/util/ordered_hash.rb +88 -42
- data/lib/mongo/util/xml_to_ruby.rb +18 -15
- data/mongo-ruby-driver.gemspec +103 -0
- data/test/mongo-qa/_common.rb +8 -0
- data/test/mongo-qa/admin +26 -0
- data/test/mongo-qa/capped +22 -0
- data/test/mongo-qa/count1 +18 -0
- data/test/mongo-qa/dbs +22 -0
- data/test/mongo-qa/find +10 -0
- data/test/mongo-qa/find1 +15 -0
- data/test/mongo-qa/gridfs_in +16 -0
- data/test/mongo-qa/gridfs_out +17 -0
- data/test/mongo-qa/indices +49 -0
- data/test/mongo-qa/remove +25 -0
- data/test/mongo-qa/stress1 +35 -0
- data/test/mongo-qa/test1 +11 -0
- data/test/mongo-qa/update +18 -0
- data/{tests → test}/test_admin.rb +25 -16
- data/test/test_bson.rb +268 -0
- data/{tests → test}/test_byte_buffer.rb +0 -0
- data/test/test_chunk.rb +84 -0
- data/test/test_collection.rb +282 -0
- data/test/test_connection.rb +101 -0
- data/test/test_cursor.rb +321 -0
- data/test/test_db.rb +196 -0
- data/test/test_db_api.rb +798 -0
- data/{tests → test}/test_db_connection.rb +4 -3
- data/test/test_grid_store.rb +284 -0
- data/{tests → test}/test_message.rb +1 -1
- data/test/test_objectid.rb +105 -0
- data/{tests → test}/test_ordered_hash.rb +55 -0
- data/{tests → test}/test_round_trip.rb +13 -9
- data/test/test_threading.rb +37 -0
- metadata +74 -32
- data/bin/validate +0 -51
- data/lib/mongo/mongo.rb +0 -74
- data/lib/mongo/types/undefined.rb +0 -31
- data/tests/test_bson.rb +0 -135
- data/tests/test_cursor.rb +0 -66
- data/tests/test_db.rb +0 -51
- data/tests/test_db_api.rb +0 -349
- data/tests/test_objectid.rb +0 -88
data/README.rdoc
CHANGED
@@ -1,23 +1,15 @@
|
|
1
1
|
= Introduction
|
2
2
|
|
3
|
-
This is a Ruby driver for
|
4
|
-
Mongo, see http://www.mongodb.org.
|
3
|
+
This is a Ruby driver for MongoDB[http://www.mongodb.org].
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
this for any production data yet.
|
9
|
-
|
10
|
-
Start by reading the XGen::Mongo::Driver::Mongo and XGen::Mongo::Driver::DB
|
11
|
-
documentation, then move on to XGen::Mongo::Driver::Collection and
|
12
|
-
XGen::Mongo::Driver::Cursor.
|
13
|
-
|
14
|
-
A quick code sample:
|
5
|
+
Here is a quick code sample. See the files in the "examples" subdirectory for
|
6
|
+
many more.
|
15
7
|
|
16
8
|
require 'mongo'
|
17
9
|
|
18
|
-
include
|
10
|
+
include Mongo
|
19
11
|
|
20
|
-
db =
|
12
|
+
db = Connection.new('localhost').db('sample-db')
|
21
13
|
coll = db.collection('test')
|
22
14
|
|
23
15
|
coll.clear
|
@@ -25,32 +17,130 @@ A quick code sample:
|
|
25
17
|
puts "There are #{coll.count()} records. Here they are:"
|
26
18
|
coll.find().each { |doc| puts doc.inspect }
|
27
19
|
|
20
|
+
This driver also includes an implementation of a GridStore class, a Ruby
|
21
|
+
interface to Mongo's GridFS storage.
|
22
|
+
|
28
23
|
= Installation
|
29
24
|
|
30
|
-
|
25
|
+
The driver's gems are hosted on Gemcutter[http://gemcutter.org]. If you haven't
|
26
|
+
installed a gem from Gemcutter before you'll need to set up Gemcutter first
|
27
|
+
|
28
|
+
$ gem install gemcutter
|
29
|
+
$ gem tumble
|
30
|
+
|
31
|
+
If (or once) you have Gemcutter setup, install the "mongo" gem by typing
|
31
32
|
|
32
|
-
$
|
33
|
+
$ gem install mongo
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
=== From the GitHub source
|
36
|
+
|
37
|
+
The source code is available at http://github.com/mongodb/mongo-ruby-driver.
|
38
|
+
You can either clone the git repository or download a tarball or zip file.
|
39
|
+
Once you have the source, you can use it from wherever you downloaded it or
|
40
|
+
you can install it as a gem from the source by typing
|
38
41
|
|
39
42
|
$ rake gem:install
|
40
43
|
|
44
|
+
=== Optional C Extension
|
45
|
+
|
46
|
+
There is a separate gem containing optional C extensions that will increase the
|
47
|
+
performance of the driver. To use the optional extensions just install the gem
|
48
|
+
by typing
|
49
|
+
|
50
|
+
$ gem install mongo_ext
|
51
|
+
|
52
|
+
To install from source type this instead
|
53
|
+
|
54
|
+
$ rake gem:install_extensions
|
41
55
|
|
42
|
-
|
56
|
+
That's all there is to it!
|
43
57
|
|
44
|
-
|
45
|
-
be running, of course.
|
58
|
+
= Examples
|
46
59
|
|
60
|
+
There are many examples in the "examples" subdirectory. Samples include using
|
61
|
+
the driver and using the GridFS class GridStore. Mongo must be running for
|
62
|
+
these examples to work, of course.
|
63
|
+
|
64
|
+
Here's how to start mongo and run the "simple.rb" example:
|
65
|
+
|
66
|
+
$ cd path/to/mongo
|
67
|
+
$ ./mongod run
|
68
|
+
... then in another window ...
|
69
|
+
$ cd path/to/mongo-ruby-driver
|
47
70
|
$ ruby examples/simple.rb
|
48
71
|
|
49
|
-
See also the test code, especially
|
72
|
+
See also the test code, especially test/test_db_api.rb.
|
73
|
+
|
74
|
+
= The Driver
|
75
|
+
|
76
|
+
Here is some simple example code:
|
77
|
+
|
78
|
+
require 'rubygems' # not required for Ruby 1.9
|
79
|
+
require 'mongo'
|
80
|
+
|
81
|
+
include Mongo
|
82
|
+
db = Connection.new.db('my-db-name')
|
83
|
+
things = db.collection('things')
|
84
|
+
|
85
|
+
things.clear
|
86
|
+
things.insert('a' => 42)
|
87
|
+
things.insert('a' => 99, 'b' => Time.now)
|
88
|
+
puts things.count # => 2
|
89
|
+
puts things.find('a' => 42).next_object.inspect # {"a"=>42}
|
90
|
+
|
91
|
+
|
92
|
+
= GridStore
|
93
|
+
|
94
|
+
The GridStore class is a Ruby implementation of Mongo's GridFS file storage
|
95
|
+
system. An instance of GridStore is like an IO object. See the rdocs for
|
96
|
+
details, and see examples/gridfs.rb for code that uses many of the GridStore
|
97
|
+
features like metadata, content type, rewind/seek/tell, etc.
|
98
|
+
|
99
|
+
Note that the GridStore class is not automatically required when you require
|
100
|
+
'mongo'. You need to require 'mongo/gridfs'.
|
101
|
+
|
102
|
+
Example code:
|
103
|
+
|
104
|
+
GridStore.open(database, 'filename', 'w') { |f|
|
105
|
+
f.puts "Hello, world!"
|
106
|
+
}
|
107
|
+
GridStore.open(database, 'filename, 'r') { |f|
|
108
|
+
puts f.read # => Hello, world!\n
|
109
|
+
}
|
110
|
+
GridStore.open(database, 'filename', 'w+') { |f|
|
111
|
+
f.puts "But wait, there's more!"
|
112
|
+
}
|
113
|
+
GridStore.open(database, 'filename, 'r') { |f|
|
114
|
+
puts f.read # => Hello, world!\nBut wait, there's more!\n
|
115
|
+
}
|
116
|
+
|
50
117
|
|
51
118
|
|
52
119
|
= Notes
|
53
120
|
|
121
|
+
== Using with Phusion Passenger
|
122
|
+
|
123
|
+
When passenger is in smart spawning mode you need to be sure that child
|
124
|
+
processes forked by passenger will create a new connection to the database.
|
125
|
+
activerecord-mongo-adapter handles this for you, so if you are using that
|
126
|
+
you shouldn't need to worry about it. Otherwise you'll either need to use
|
127
|
+
conservative spawning[http://www.modrails.org/documentation/Users%20guide.html#RailsSpawnMethod]
|
128
|
+
or handle reconnecting when passenger forks a new process:
|
129
|
+
|
130
|
+
if defined?(PhusionPassenger)
|
131
|
+
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
132
|
+
if forked
|
133
|
+
# Call db.connect_to_master to reconnect here
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
The above code should be put in _environment.rb_ or an initialization
|
139
|
+
script.
|
140
|
+
|
141
|
+
See this thread[http://groups.google.com/group/mongodb-user/browse_thread/thread/f31e2d23de38136a]
|
142
|
+
for more details on this issue.
|
143
|
+
|
54
144
|
== String Encoding
|
55
145
|
|
56
146
|
The BSON ("Binary JSON") format used to communicate with Mongo requires that
|
@@ -62,7 +152,101 @@ read from Mongo will have their character encodings set to UTF-8.
|
|
62
152
|
|
63
153
|
When used with Ruby 1.8, the bytes in each string are written to and read from
|
64
154
|
Mongo as-is. If the string is ASCII all is well, because ASCII is a subset of
|
65
|
-
UTF-8. If the string is not ASCII then it may not be a well-formed UTF-8
|
155
|
+
UTF-8. If the string is not ASCII then it may not be a well-formed UTF-8
|
156
|
+
string.
|
157
|
+
|
158
|
+
== Primary Keys
|
159
|
+
|
160
|
+
The field _id is a primary key. It is treated specially by the database, and
|
161
|
+
its use makes many operations more efficient. The value of an _id may be of
|
162
|
+
any type. The database itself inserts an _id value if none is specified when
|
163
|
+
a record is inserted.
|
164
|
+
|
165
|
+
=== Primary Key Factories
|
166
|
+
|
167
|
+
A primary key factory is a class you supply to a DB object that knows how to
|
168
|
+
generate _id values. If you want to control _id values or even their types,
|
169
|
+
using a PK factory lets you do so.
|
170
|
+
|
171
|
+
You can tell the Ruby Mongo driver how to create primary keys by passing in
|
172
|
+
the :pk option to the Connection#db method.
|
173
|
+
|
174
|
+
include Mongo
|
175
|
+
db = Connection.new.db('dbname', :pk => MyPKFactory.new)
|
176
|
+
|
177
|
+
A primary key factory object must respond to :create_pk, which should take a
|
178
|
+
hash and return a hash which merges the original hash with any primary key
|
179
|
+
fields the factory wishes to inject. NOTE: if the object already has a primary
|
180
|
+
key, the factory should not inject a new key; this means that the object is
|
181
|
+
being used in a repsert but it already exists. The idea here is that whenever
|
182
|
+
a record is inserted, the :pk object's +create_pk+ method will be called and
|
183
|
+
the new hash returned will be inserted.
|
184
|
+
|
185
|
+
Here is a sample primary key factory, taken from the tests:
|
186
|
+
|
187
|
+
class TestPKFactory
|
188
|
+
def create_pk(row)
|
189
|
+
row['_id'] ||= Mongo::ObjectID.new
|
190
|
+
row
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
Here's a slightly more sophisticated one that handles both symbol and string
|
195
|
+
keys. This is the PKFactory that comes with the MongoRecord code (an
|
196
|
+
ActiveRecord-like framework for non-Rails apps) and the AR Mongo adapter code
|
197
|
+
(for Rails):
|
198
|
+
|
199
|
+
class PKFactory
|
200
|
+
def create_pk(row)
|
201
|
+
return row if row[:_id]
|
202
|
+
row.delete(:_id) # in case it exists but the value is nil
|
203
|
+
row['_id'] ||= Mongo::ObjectID.new
|
204
|
+
row
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
A database's PK factory object may be set either when a DB object is created
|
209
|
+
or immediately after you obtain it, but only once. The only reason it is
|
210
|
+
changeable at all is so that libraries such as MongoRecord that use this
|
211
|
+
driver can set the PK factory after obtaining the database but before using it
|
212
|
+
for the first time.
|
213
|
+
|
214
|
+
== The DB Class
|
215
|
+
|
216
|
+
=== Primary Key factories
|
217
|
+
|
218
|
+
See the section on "Primary Keys" above.
|
219
|
+
|
220
|
+
=== Strict mode
|
221
|
+
|
222
|
+
Each database has an optional strict mode. If strict mode is on, then asking
|
223
|
+
for a collection that does not exist will raise an error, as will asking to
|
224
|
+
create a collection that already exists. Note that both these operations are
|
225
|
+
completely harmless; strict mode is a programmer convenience only.
|
226
|
+
|
227
|
+
To turn on strict mode, either pass in :strict => true when obtaining a DB
|
228
|
+
object or call the :strict= method:
|
229
|
+
|
230
|
+
db = Connection.new.db('dbname', :strict => true)
|
231
|
+
# I'm feeling lax
|
232
|
+
db.strict = false
|
233
|
+
# No, I'm not!
|
234
|
+
db.strict = true
|
235
|
+
|
236
|
+
The method DB#strict? returns the current value of that flag.
|
237
|
+
|
238
|
+
== Cursors
|
239
|
+
|
240
|
+
Random cursor fun facts:
|
241
|
+
|
242
|
+
- Cursors are enumerable.
|
243
|
+
|
244
|
+
- The query doesn't get run until you actually attempt to retrieve data from a
|
245
|
+
cursor.
|
246
|
+
|
247
|
+
- Cursors have a to_a method.
|
248
|
+
|
249
|
+
|
66
250
|
|
67
251
|
= Testing
|
68
252
|
|
@@ -70,21 +254,23 @@ If you have the source code, you can run the tests.
|
|
70
254
|
|
71
255
|
$ rake test
|
72
256
|
|
73
|
-
The tests assume that the Mongo database is running on the default port.
|
257
|
+
The tests assume that the Mongo database is running on the default port. You
|
258
|
+
can override the default host (localhost) and port (Connection::DEFAULT_PORT) by
|
259
|
+
using the environment variables MONGO_RUBY_DRIVER_HOST and
|
260
|
+
MONGO_RUBY_DRIVER_PORT.
|
74
261
|
|
75
262
|
The project mongo-qa (http://github.com/mongodb/mongo-qa) contains many more
|
76
263
|
Mongo driver tests that are language independent. To run thoses tests as part
|
77
|
-
of the "rake test" task,
|
264
|
+
of the "rake test" task, download the code "next to" this directory. So, after
|
265
|
+
installing the mongo-qa code you would have these two directories next to each
|
266
|
+
other:
|
78
267
|
|
79
|
-
$
|
268
|
+
$ ls
|
269
|
+
mongo-qa
|
270
|
+
mongo-ruby-driver
|
80
271
|
$ rake test
|
81
272
|
|
82
|
-
The
|
83
|
-
in a directory named mongo-qa. If the directory already exists, then the
|
84
|
-
mongo_qa task uses "git pull" to updated the code that's there. The Ruby
|
85
|
-
driver tests will then use some of the data files from that project when it
|
86
|
-
runs BSON tests. You can delete this directory at any time if you don't want
|
87
|
-
to run those tests any more.
|
273
|
+
The tests run just fine if the mongo-qa directory is not there.
|
88
274
|
|
89
275
|
Additionally, the script bin/validate is used by the mongo-qa project's
|
90
276
|
validator script.
|
@@ -92,7 +278,7 @@ validator script.
|
|
92
278
|
|
93
279
|
= Documentation
|
94
280
|
|
95
|
-
This documentation is available online at http://
|
281
|
+
This documentation is available online at http://api.mongodb.org/ruby. You can
|
96
282
|
generate the documentation if you have the source by typing
|
97
283
|
|
98
284
|
$ rake rdoc
|
@@ -104,59 +290,70 @@ Then open the file html/index.html.
|
|
104
290
|
|
105
291
|
See the git log comments.
|
106
292
|
|
293
|
+
= Credits
|
107
294
|
|
108
|
-
|
295
|
+
Adrian Madrid, aemadrid@gmail.com
|
296
|
+
* bin/mongo_console
|
297
|
+
* examples/benchmarks.rb
|
298
|
+
* examples/irb.rb
|
299
|
+
* Modifications to examples/simple.rb
|
300
|
+
* Found plenty of bugs and missing features.
|
301
|
+
* Ruby 1.9 support.
|
302
|
+
* Gem support.
|
303
|
+
* Many other code suggestions and improvements.
|
109
304
|
|
110
|
-
|
111
|
-
|
112
|
-
would have to send as a string), but this is still under discussion.
|
305
|
+
Aman Gupta, aman@tmm1.net
|
306
|
+
* Collection#save
|
113
307
|
|
114
|
-
|
308
|
+
Jon Crosby, jon@joncrosby.me
|
309
|
+
* Some code clean-up
|
115
310
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
is the master before proceeding.
|
311
|
+
John Nunemaker, http://railstips.org
|
312
|
+
* Collection#create_index takes symbols as well as strings
|
313
|
+
* Fix for Collection#save
|
120
314
|
|
121
|
-
|
315
|
+
David James, djames@sunlightfoundation.com
|
316
|
+
* Fix dates to return as UTC
|
122
317
|
|
123
|
-
|
318
|
+
Paul Dlug, paul.dlug@gmail.com
|
319
|
+
* Generate _id on the client side if not provided
|
320
|
+
* Collection#insert and Collection#save return _id
|
124
321
|
|
125
|
-
|
322
|
+
Durran Jordan and Les Hill, durran@gmail.com
|
323
|
+
* DB#collections
|
126
324
|
|
127
|
-
|
128
|
-
|
325
|
+
Cyril Mougel, cyril.mougel@gmail.com
|
326
|
+
* Initial logging support
|
129
327
|
|
130
|
-
|
131
|
-
|
132
|
-
is not a lightweight operation for the particular driver.)
|
328
|
+
Jack Chen, chendo on github
|
329
|
+
* Test case + fix for deserializing pre-epoch Time instances
|
133
330
|
|
331
|
+
Kyle Banker, banker on github
|
332
|
+
* #limit and #skip methods for Cursor instances
|
134
333
|
|
135
|
-
|
334
|
+
Michael Bernstein, mrb on github
|
335
|
+
* #sort method for Cursor instances
|
136
336
|
|
137
|
-
|
138
|
-
*
|
139
|
-
|
140
|
-
|
141
|
-
*
|
142
|
-
* Found plenty of bugs and missing features.
|
143
|
-
* Ruby 1.9 support.
|
144
|
-
* Gem support.
|
145
|
-
* Many other code suggestions and improvements.
|
337
|
+
Paulo Ahahgon, pahagon on github
|
338
|
+
* removed hard limit
|
339
|
+
|
340
|
+
Les Hill, leshill on github
|
341
|
+
* OrderedHash#each returns self
|
146
342
|
|
147
343
|
|
148
344
|
= License
|
149
345
|
|
150
|
-
Copyright
|
346
|
+
Copyright 2008-2009 10gen Inc.
|
347
|
+
|
348
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
349
|
+
you may not use this file except in compliance with the License.
|
350
|
+
You may obtain a copy of the License at
|
151
351
|
|
152
|
-
|
153
|
-
the terms of the GNU Affero General Public License, version 3, as published by
|
154
|
-
the Free Software Foundation.
|
352
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
155
353
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
354
|
+
Unless required by applicable law or agreed to in writing, software
|
355
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
356
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
357
|
+
See the License for the specific language governing permissions and
|
358
|
+
limitations under the License.
|
160
359
|
|
161
|
-
See http://www.gnu.org/licenses for a copy of the GNU Affero General Public
|
162
|
-
License.
|
data/Rakefile
CHANGED
@@ -4,59 +4,27 @@ require 'fileutils'
|
|
4
4
|
require 'rake'
|
5
5
|
require 'rake/testtask'
|
6
6
|
require 'rake/gempackagetask'
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
GEM_VERSION = '0.1.0'
|
11
|
-
SUMMARY = 'Simple pure-Ruby driver for the 10gen Mongo DB'
|
12
|
-
DESCRIPTION = 'This is a simple pure-Ruby driver for the 10gen Mongo DB. For more information about Mongo, see http://www.mongodb.org.'
|
13
|
-
AUTHOR = 'Jim Menard'
|
14
|
-
EMAIL = 'jimm@io.com'
|
15
|
-
HOMEPAGE = 'http://www.mongodb.org'
|
16
|
-
RUBYFORGE_USER = 'jimm'
|
17
|
-
|
18
|
-
spec = Gem::Specification.new do |s|
|
19
|
-
s.name = GEM
|
20
|
-
s.version = GEM_VERSION
|
21
|
-
s.platform = Gem::Platform::RUBY
|
22
|
-
s.summary = SUMMARY
|
23
|
-
s.description = DESCRIPTION
|
24
|
-
|
25
|
-
s.require_paths = ['lib']
|
26
|
-
|
27
|
-
s.files = FileList['bin/*', 'lib/**/*.rb', 'tests/**/*.rb', '[A-Z]*'].to_a
|
28
|
-
|
29
|
-
s.bindir = 'bin'
|
30
|
-
s.executables = %w( mongo_console )
|
31
|
-
s.has_rdoc = true
|
32
|
-
|
33
|
-
s.author = AUTHOR
|
34
|
-
s.email = EMAIL
|
35
|
-
s.homepage = HOMEPAGE
|
36
|
-
|
37
|
-
s.rubyforge_project = GEM # GitHub bug, gem isn't being build when this miss
|
7
|
+
begin
|
8
|
+
require 'rake/contrib/rubyforgepublisher'
|
9
|
+
rescue LoadError
|
38
10
|
end
|
11
|
+
require 'rbconfig'
|
12
|
+
include Config
|
13
|
+
|
14
|
+
gem_command = "gem"
|
15
|
+
gem_command = "gem1.9" if $0.match(/1\.9$/) # use gem1.9 if we used rake1.9
|
39
16
|
|
40
17
|
# NOTE: some of the tests assume Mongo is running
|
41
18
|
Rake::TestTask.new do |t|
|
42
|
-
t.test_files = FileList['
|
43
|
-
end
|
44
|
-
|
45
|
-
desc "Clone or pull (update) the mongo-qa project used for testing"
|
46
|
-
task :mongo_qa do
|
47
|
-
if File.exist?('mongo-qa')
|
48
|
-
Dir.chdir('mongo-qa') do
|
49
|
-
system('git pull')
|
50
|
-
end
|
51
|
-
else
|
52
|
-
system('git clone git://github.com/mongodb/mongo-qa.git')
|
53
|
-
end
|
19
|
+
t.test_files = FileList['test/test*.rb']
|
54
20
|
end
|
55
21
|
|
56
22
|
desc "Generate documentation"
|
57
23
|
task :rdoc do
|
24
|
+
version = eval(File.read("mongo-ruby-driver.gemspec")).version
|
25
|
+
out = File.join('html', version.to_s)
|
58
26
|
FileUtils.rm_rf('html')
|
59
|
-
system "rdoc --main README.rdoc --op
|
27
|
+
system "rdoc --main README.rdoc --op #{out} --inline-source --quiet README.rdoc `find lib -name '*.rb'`"
|
60
28
|
end
|
61
29
|
|
62
30
|
desc "Publish documentation to mongo.rubyforge.org"
|
@@ -65,27 +33,24 @@ task :publish => [:rdoc] do
|
|
65
33
|
Rake::RubyForgePublisher.new(GEM, RUBYFORGE_USER).upload
|
66
34
|
end
|
67
35
|
|
68
|
-
namespace :gem do
|
69
|
-
|
70
|
-
Rake::GemPackageTask.new(spec) do |pkg|
|
71
|
-
pkg.gem_spec = spec
|
72
|
-
end
|
36
|
+
namespace :gem do
|
73
37
|
|
74
38
|
desc "Install the gem locally"
|
75
|
-
task :install
|
76
|
-
sh
|
39
|
+
task :install do
|
40
|
+
sh <<EOS
|
41
|
+
#{gem_command} build mongo-ruby-driver.gemspec &&
|
42
|
+
sudo #{gem_command} install mongo-*.gem &&
|
43
|
+
rm mongo-*.gem
|
44
|
+
EOS
|
77
45
|
end
|
78
|
-
|
79
|
-
desc "Install the
|
80
|
-
task :
|
81
|
-
sh
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
File.open("#{GEM}.gemspec", "w") do |file|
|
87
|
-
file.puts spec.to_ruby
|
88
|
-
end
|
46
|
+
|
47
|
+
desc "Install the optional c extensions"
|
48
|
+
task :install_extensions do
|
49
|
+
sh <<EOS
|
50
|
+
#{gem_command} build mongo-extensions.gemspec &&
|
51
|
+
sudo #{gem_command} install mongo_ext-*.gem &&
|
52
|
+
rm mongo_ext-*.gem
|
53
|
+
EOS
|
89
54
|
end
|
90
55
|
|
91
56
|
end
|