Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

minor: whitespace fix

  • Loading branch information...
commit 03b0cd5cd5b09c781248b9ec949291c62b57d6cb 1 parent f1878c7
@pawelpacana pawelpacana authored committed
View
2  examples/legacy.rb
@@ -27,7 +27,7 @@
docs.each do |doc|
puts "Revolution ##{doc['revolution']}"
end
- end
+ end
collection.drop
View
10 examples/readme.rb
@@ -11,15 +11,15 @@
end
#find returns an EM::Mongo::Cursor
- cursor = collection.find
+ cursor = collection.find
#most cursor methods return an EM::Mongo::RequestResponse,
#which is an EventMachine::Deferrable
- resp = cursor.to_a
+ resp = cursor.to_a
- #when em-mongo IO methods succeed, they
+ #when em-mongo IO methods succeed, they
#will always call back with the return
- #value you would have expected from the
+ #value you would have expected from the
#synchronous version of the method from
#the mongo-ruby-driver
resp.callback do |documents|
@@ -39,7 +39,7 @@
if doc
puts "Revolution ##{doc['revolution']}"
end
- end
+ end
#add an index
collection.create_index [[:revolution, -1]]
View
4 lib/em-mongo.rb
@@ -9,9 +9,9 @@ module EM::Mongo
module Version
STRING = File.read(File.dirname(__FILE__) + '/../VERSION')
- MAJOR, MINOR, TINY = STRING.split('.')
+ MAJOR, MINOR, TINY = STRING.split('.')
end
-
+
NAME = 'em-mongo'
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
View
26 lib/em-mongo/collection.rb
@@ -121,14 +121,14 @@ def find(selector={}, opts={})
raise RuntimeError, "Unknown options [#{opts.inspect}]" unless opts.empty?
EM::Mongo::Cursor.new(self, {
- :selector => selector,
- :fields => fields,
- :skip => skip,
+ :selector => selector,
+ :fields => fields,
+ :skip => skip,
:limit => limit,
- :order => sort,
- :hint => hint,
- :snapshot => snapshot,
- :timeout => timeout,
+ :order => sort,
+ :hint => hint,
+ :snapshot => snapshot,
+ :timeout => timeout,
:batch_size => batch_size,
:transformer => transformer,
:max_scan => max_scan,
@@ -142,8 +142,8 @@ def find(selector={}, opts={})
# @return [EM::Mongo::RequestResponse]
# calls back with a single document or nil if no result is found.
#
- # @param [Hash, ObjectId, Nil] spec_or_object_id a hash specifying elements
- # which must be present for a document to be included in the result set or an
+ # @param [Hash, ObjectId, Nil] spec_or_object_id a hash specifying elements
+ # which must be present for a document to be included in the result set or an
# instance of ObjectId to be used as the value for an _id query.
# If nil, an empty selector, {}, will be used.
#
@@ -256,7 +256,7 @@ def update(selector, document, opts={})
# @option opts [Boolean] :upsert (+false+) if true, performs an upsert (update or insert)
# @option opts [Boolean] :multi (+false+) update all documents matching the selector, as opposed to
# just the first matching document. Note: only works in MongoDB 1.1.3 or later.
- # @option opts [Boolean] :safe (+true+)
+ # @option opts [Boolean] :safe (+true+)
# If true, check that the save succeeded. OperationFailure
# will be raised on an error. Note that a safe check requires an extra
# round-trip to the database. Safe options provided here will override any safe
@@ -717,7 +717,7 @@ def insert_documents(documents, collection_name=@name, check_keys = true, safe_o
message.put_binary(BSON::BSON_CODER.serialize(doc, check_keys, true).to_s)
end
raise InvalidOperation, "Exceded maximum insert size of 16,000,000 bytes" if message.size > 16_000_000
-
+
ids = documents.collect { |o| o[:_id] || o['_id'] }
if safe_options[:safe]
@@ -773,12 +773,12 @@ def parse_index_spec(spec)
if [EM::Mongo::ASCENDING, EM::Mongo::DESCENDING, EM::Mongo::GEO2D].include?(f[1])
field_spec[f[0].to_s] = f[1]
else
- raise MongoArgumentError, "Invalid index field #{f[1].inspect}; " +
+ raise MongoArgumentError, "Invalid index field #{f[1].inspect}; " +
"should be one of Mongo::ASCENDING (1), Mongo::DESCENDING (-1) or Mongo::GEO2D ('2d')."
end
end
else
- raise MongoArgumentError, "Invalid index specification #{spec.inspect}; " +
+ raise MongoArgumentError, "Invalid index specification #{spec.inspect}; " +
"should be either a string, symbol, or an array of arrays."
end
field_spec
View
4 lib/em-mongo/connection.rb
@@ -84,7 +84,7 @@ def prepare_safe_message(message,options)
message.append!(last_error_message)
last_error_id
end
-
+
def message_headers(operation, request_id, message)
headers = BSON::ByteBuffer.new
headers.put_int(16 + message.size)
@@ -264,7 +264,7 @@ def close
def connected?
@em_connection.connected?
end
-
+
def send_command(*args, &block);@em_connection.send_command(*args, &block);end
# Is it okay to connect to a slave?
View
4 lib/em-mongo/conversions.rb
@@ -25,7 +25,7 @@ module Conversions
DESCENDING_CONVERSION = ["descending", "desc", "-1"]
# Converts the supplied +Array+ to a +Hash+ to pass to mongo as
- # sorting parameters. The returned +Hash+ will vary depending
+ # sorting parameters. The returned +Hash+ will vary depending
# on whether the passed +Array+ is one or two dimensional.
#
# Example:
@@ -67,7 +67,7 @@ def string_as_sort_parameters(value)
{ str => 1 }
end
- # Converts the +String+, +Symbol+, or +Integer+ to the
+ # Converts the +String+, +Symbol+, or +Integer+ to the
# corresponding sort value in MongoDB.
#
# Valid conversions (case-insensitive):
View
12 lib/em-mongo/cursor.rb
@@ -100,7 +100,7 @@ def check_and_transform_document(doc, response)
return response.succeed(nil) if doc.nil?
if doc['$err']
-
+
err = doc['$err']
# If the server has stopped being the master (e.g., it's one of a
@@ -112,7 +112,7 @@ def check_and_transform_document(doc, response)
else
response.fail([OperationFailure, err])
end
-
+
else
response.succeed(
@transformer ? @transformer.call(doc) : doc
@@ -180,7 +180,7 @@ def count(skip_and_limit = false)
# This method overrides any sort order specified in the Collection#find
# method, and only the last sort applied has an effect.
#
- # @param [Symbol, Array] key_or_list either 1) a key to sort by or 2)
+ # @param [Symbol, Array] key_or_list either 1) a key to sort by or 2)
# an array of [key, direction] pairs to sort by. Direction should
# be specified as EM::Mongo::ASCENDING (or :ascending / :asc) or EM::Mongo::DESCENDING (or :descending / :desc)
#
@@ -308,10 +308,10 @@ def to_a
elsif doc
items << doc
else
- response.succeed(items)
+ response.succeed(items)
end
end
- response
+ response
end
# Get the explain plan for this cursor.
@@ -322,7 +322,7 @@ def to_a
def explain
response = RequestResponse.new
c = Cursor.new(@collection, query_options_hash.merge(:limit => -@limit.abs, :explain => true))
-
+
exp_response = c.next_document
exp_response.callback do |explanation|
c.close
View
10 lib/em-mongo/database.rb
@@ -177,7 +177,7 @@ def drop_index(collection_name, index_name)
oh[:index] = index_name.to_s
cmd_resp = command(oh, :check_response => false)
cmd_resp.callback do |doc|
- if EM::Mongo::Support.ok?(doc)
+ if EM::Mongo::Support.ok?(doc)
response.succeed(true)
else
response.fail [MongoDBError, "Error with drop_index command: #{doc.inspect}"]
@@ -275,7 +275,7 @@ def full_collection_name(collection_name)
"#{name}.#{collection_name}"
end
-
+
# Send a command to the database.
#
@@ -300,7 +300,7 @@ def full_collection_name(collection_name)
def command(selector, opts={})
check_response = opts.fetch(:check_response, true)
raise MongoArgumentError, "command must be given a selector" unless selector.is_a?(Hash) && !selector.empty?
-
+
if selector.keys.length > 1 && RUBY_VERSION < '1.9' && selector.class != BSON::OrderedHash
raise MongoArgumentError, "DB#command requires an OrderedHash when hash contains multiple keys"
end
@@ -308,7 +308,7 @@ def command(selector, opts={})
response = RequestResponse.new
cmd_resp = Cursor.new(self.collection(SYSTEM_COMMAND_COLLECTION), :limit => -1, :selector => selector).next_document
- cmd_resp.callback do |doc|
+ cmd_resp.callback do |doc|
if doc.nil?
response.fail([OperationFailure, "Database command '#{selector.keys.first}' failed: returned null."])
elsif (check_response && !EM::Mongo::Support.ok?(doc))
@@ -346,7 +346,7 @@ def authenticate(username, password)
auth = BSON::OrderedHash.new
auth['authenticate'] = 1
auth['user'] = username
- auth['nonce'] = res['nonce']
+ auth['nonce'] = res['nonce']
auth['key'] = EM::Mongo::Support.auth_key(username, password, res['nonce'])
auth_resp2 = self.collection(SYSTEM_COMMAND_COLLECTION).first(auth)
View
1  lib/em-mongo/request_response.rb
@@ -31,4 +31,3 @@ def error
end
end
-
View
4 lib/em-mongo/server_response.rb
@@ -1,7 +1,7 @@
module EM::Mongo
class ServerResponse
- attr_reader :size, :request_id, :response_to, :op,
+ attr_reader :size, :request_id, :response_to, :op,
:result_flags, :cursor_id, :starting_from,
:number_returned, :docs, :connection
@@ -27,6 +27,6 @@ def initialize(buffer, connection)
BSON::BSON_CODER.deserialize(buf)
end
end
-
+
end
end
View
30 spec/integration/collection_spec.rb
@@ -240,7 +240,7 @@
done
end
end
-
+
it "should respond with an error when an invalid document is saved" do
@conn, @coll = connection_and_collection('safe.test')
@coll.create_index("hello", :unique => true)
@@ -285,8 +285,8 @@
@conn, @coll = connection_and_collection('safe.update.test')
@coll.create_index("x", :unique => true)
@coll.insert({"x" => 5})
- @coll.insert({"x" => 10})
-
+ @coll.insert({"x" => 10})
+
@coll.safe_update({},{"x" => 10}).errback do |err|
err[0].should == EM::Mongo::OperationFailure
done
@@ -297,7 +297,7 @@
end
describe "save" do
-
+
it "should insert a record when no id is present" do
@conn, @coll = connection_and_collection
id = @coll.save("x" => 1)
@@ -325,8 +325,8 @@
@conn, @coll = connection_and_collection('safe.save.test')
@coll.create_index("x", :unique => true)
@coll.save({"x" => 5})
- @coll.save({"x" => 5})
-
+ @coll.save({"x" => 5})
+
@coll.safe_save({"x" => 5}).errback do |err|
err[0].should == EM::Mongo::OperationFailure
done
@@ -363,7 +363,7 @@
end
describe "find_and_modify" do
-
+
it "should find and modify a document" do
@conn, @coll = connection_and_collection
@coll << { :a => 1, :processed => false }
@@ -448,7 +448,7 @@
res = @coll.map_reduce(m, r, :query => {"user_id" => {"$gt" => 1}}, :out => 'foo')
res.callback do |collection|
collection.count .callback do |c|
- c.should == 2
+ c.should == 2
collection.find_one({"_id" => 2}).callback do |doc|
doc.should_not be_nil
collection.find_one({"_id" => 3}).callback do |doc2|
@@ -641,7 +641,7 @@
done
end
end
-
+
it "should create a geospatial index" do
@conn, @geo = connection_and_collection('geo')
@geo.save({'loc' => [-100, 100]})
@@ -649,8 +649,8 @@
@geo.index_information.callback do |info|
info['loc_2d'].should_not be_nil
done
- end
- end
+ end
+ end
it "should create a unique index" do
@conn, @collection = connection_and_collection('test-collection')
@@ -722,21 +722,21 @@
done
end
end
-
+
it "should drop an index" do
@conn, @collection = connection_and_collection('test-collection')
@collection.create_index([['a',EM::Mongo::ASCENDING]])
@collection.index_information.callback do |info|
info['a_1'].should_not be_nil
- @collection.drop_index([['a',EM::Mongo::ASCENDING]]).callback do
+ @collection.drop_index([['a',EM::Mongo::ASCENDING]]).callback do
@collection.index_information.callback do |info|
info['a_1'].should be_nil
done
end
end
end
-
- end
+
+ end
end
it 'should handle multiple pending queries' do
View
4 spec/integration/cursor_spec.rb
@@ -255,7 +255,7 @@
cursor = EM::Mongo::Cursor.new(@coll).sort(["x", :desc])
cursor.next_document.callback do |first|
lambda { cursor.sort("x",1) }.should raise_error EM::Mongo::InvalidOperation
- done
+ done
end
end
@@ -267,7 +267,7 @@
cursor = EM::Mongo::Cursor.new(@coll).sort(["x", :desc])
cursor.next_document.callback do |first|
first["x"].year.should == 2004
- done
+ done
end
end
View
14 spec/integration/database_spec.rb
@@ -7,7 +7,7 @@
@conn = EM::Mongo::Connection.new
@db = @conn.db
@db.collection(EM::Mongo::Database::SYSTEM_USER_COLLECTION).remove({})
- @db.add_user('test', 'test').callback do |res|
+ @db.add_user('test', 'test').callback do |res|
res.should_not == nil
res.should be_a_kind_of(BSON::ObjectId)
done
@@ -22,7 +22,7 @@
res.should == true
done
end
- end
+ end
it "should create a collection" do
@conn = EM::Mongo::Connection.new
@@ -76,15 +76,15 @@
end
end
end
-
+
it 'should cache collections correctly' do
@conn = EM::Mongo::Connection.new
@db = @conn.db
a = @db.collection('first_collection')
b = @db.collection('second_collection')
- a.should_not == b
+ a.should_not == b
@db.collection('first_collection').should == a
- @db.collection('second_collection').should == b
+ @db.collection('second_collection').should == b
done
end
@@ -94,7 +94,7 @@
@conn = EM::Mongo::Connection.new
@db = @conn.db
@db.reset_error_history.callback do
- @db.get_last_error.callback do |doc|
+ @db.get_last_error.callback do |doc|
doc['err'].should be_nil
done
end
@@ -116,7 +116,7 @@
@conn = EM::Mongo::Connection.new
@db = @conn.db
@db.command({:forceerror=>1}, :check_response => false).callback do
- @db.get_last_error.callback do |doc|
+ @db.get_last_error.callback do |doc|
doc['err'].should_not be_nil
done
end
View
10 spec/integration/request_response_spec.rb
@@ -23,7 +23,7 @@
end
context "when succeeded" do
before(:each) { @response.succeed [:some,:data] }
-
+
it "should have completed" do
@response.completed?.should be_true
end
@@ -37,8 +37,8 @@
@response.data.should == [:some, :data]
end
it "should not have an error" do
- @response.error.should be_nil
- end
+ @response.error.should be_nil
+ end
end
context "when failed" do
before(:each) { @response.fail [RuntimeError, "crap!"]}
@@ -56,8 +56,8 @@
@response.data.should be_nil
end
it "should have an error" do
- @response.error.should == [RuntimeError, "crap!"]
- end
+ @response.error.should == [RuntimeError, "crap!"]
+ end
end
end
View
2  spec/spec_helper.rb
@@ -13,7 +13,7 @@
require "em-spec/rspec"
def connection_and_collection(collection_name=EM::Mongo::DEFAULT_NS)
- conn = EMMongo::Connection.new
+ conn = EMMongo::Connection.new
return conn, collection(conn, collection_name)
end
Please sign in to comment.
Something went wrong with that request. Please try again.