Permalink
Browse files

Check if already bson object id first. Assumes that is most common.

  • Loading branch information...
1 parent 6e56618 commit 966abc94b567b71d4cf0599391973da4fd515fe5 @jnunemaker jnunemaker committed May 28, 2011
Showing with 6 additions and 9 deletions.
  1. +6 −9 lib/plucky.rb
View
@@ -15,16 +15,13 @@ module Pagination
end
def self.to_object_id(value)
- if value.nil? || (value.respond_to?(:empty?) && value.empty?)
- nil
- elsif value.is_a?(BSON::ObjectId)
- value
+ return value if value.is_a?(BSON::ObjectId)
+ return nil if value.nil? || (value.respond_to?(:empty?) && value.empty?)
+
+ if BSON::ObjectId.legal?(value.to_s)
+ BSON::ObjectId.from_string(value.to_s)
else
- if BSON::ObjectId.legal?(value.to_s)
- BSON::ObjectId.from_string(value.to_s)
- else
- value
- end
+ value
end
end
end

0 comments on commit 966abc9

Please sign in to comment.