Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Don't do type checking when polymorphism will do.
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Jun 20, 2012
1 parent 7009e8e commit 86d32d9
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/moped/connection.rb
Expand Up @@ -116,7 +116,7 @@ def read
# @since 1.0.0
def receive_replies(operations)
operations.map do |operation|
read if operation.is_a?(Protocol::Query) || operation.is_a?(Protocol::GetMore)
operation.receive_replies(self)
end
end

Expand Down
3 changes: 0 additions & 3 deletions lib/moped/protocol/command.rb
Expand Up @@ -18,11 +18,8 @@ def initialize(database, command, options = {})

def log_inspect
type = "COMMAND"

"%-12s database=%s command=%s" % [type, database, selector.inspect]
end

end

end
end
15 changes: 14 additions & 1 deletion lib/moped/protocol/get_more.rb
Expand Up @@ -72,9 +72,22 @@ def initialize(database, collection, cursor_id, limit, options = {})

def log_inspect
type = "GET_MORE"

"%-12s database=%s collection=%s limit=%s cursor_id=%s" % [type, database, collection, limit, cursor_id]
end

# Receive replies to the message.
#
# @example Receive replies.
# message.receive_replies(connection)
#
# @param [ Connection ] connection The connection.
#
# @return [ Protocol::Reply ] The reply.
#
# @since 1.0.0
def receive_replies(connection)
connection.read
end
end
end
end
13 changes: 13 additions & 0 deletions lib/moped/protocol/message.rb
Expand Up @@ -283,6 +283,19 @@ def inherited(subclass)

end

# Default implementation for a message is to do nothing when receiving
# replies.
#
# @example Receive replies.
# message.receive_replies(connection)
#
# @param [ Connection ] connection The connection.
#
# @since 1.0.0
#
# @return [ nil ] nil.
def receive_replies(connection); end

# Serializes the message and all of its fields to a new buffer or to the
# provided buffer.
#
Expand Down
16 changes: 13 additions & 3 deletions lib/moped/protocol/query.rb
Expand Up @@ -111,7 +111,6 @@ def initialize(database, collection, selector, options = {})

def log_inspect
type = "QUERY"

fields = []
fields << ["%-12s", type]
fields << ["database=%s", database]
Expand All @@ -121,12 +120,23 @@ def log_inspect
fields << ["limit=%s", limit.inspect]
fields << ["skip=%s", skip.inspect]
fields << ["fields=%s", self.fields.inspect]

f, v = fields.transpose

f.join(" ") % v
end

# Receive replies to the message.
#
# @example Receive replies.
# message.receive_replies(connection)
#
# @param [ Connection ] connection The connection.
#
# @return [ Protocol::Reply ] The reply.
#
# @since 1.0.0
def receive_replies(connection)
connection.read
end
end
end
end

0 comments on commit 86d32d9

Please sign in to comment.