Skip to content

Commit

Permalink
minor: whitespace fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mostlyobvious authored and bcg committed Sep 10, 2011
1 parent f1878c7 commit 03b0cd5
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 69 deletions.
2 changes: 1 addition & 1 deletion examples/legacy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
docs.each do |doc|
puts "Revolution ##{doc['revolution']}"
end
end
end

collection.drop

Expand Down
10 changes: 5 additions & 5 deletions examples/readme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -39,7 +39,7 @@
if doc
puts "Revolution ##{doc['revolution']}"
end
end
end

#add an index
collection.create_index [[:revolution, -1]]
Expand Down
4 changes: 2 additions & 2 deletions lib/em-mongo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions lib/em-mongo/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
#
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/em-mongo/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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?
Expand Down
4 changes: 2 additions & 2 deletions lib/em-mongo/conversions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions lib/em-mongo/cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
#
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/em-mongo/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"]
Expand Down Expand Up @@ -275,7 +275,7 @@ def full_collection_name(collection_name)
"#{name}.#{collection_name}"
end



# Send a command to the database.
#
Expand All @@ -300,15 +300,15 @@ 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

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))
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion lib/em-mongo/request_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ def error
end
end


4 changes: 2 additions & 2 deletions lib/em-mongo/server_response.rb
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -27,6 +27,6 @@ def initialize(buffer, connection)
BSON::BSON_CODER.deserialize(buf)
end
end

end
end
30 changes: 15 additions & 15 deletions spec/integration/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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|
Expand Down Expand Up @@ -641,16 +641,16 @@
done
end
end

it "should create a geospatial index" do
@conn, @geo = connection_and_collection('geo')
@geo.save({'loc' => [-100, 100]})
@geo.create_index([['loc', EM::Mongo::GEO2D]])
@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')
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/integration/cursor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
Loading

0 comments on commit 03b0cd5

Please sign in to comment.