diff --git a/lib/rack/gridfs/endpoint/base.rb b/lib/rack/gridfs/endpoint/base.rb index b54c3eb..b7e8cf6 100644 --- a/lib/rack/gridfs/endpoint/base.rb +++ b/lib/rack/gridfs/endpoint/base.rb @@ -4,11 +4,7 @@ class Endpoint module Base def initialize(options = {}) - @options = { - :hostname => 'localhost', - :port => Mongo::Connection::DEFAULT_PORT, - :lookup => :id - }.merge(options) + @options = default_options.merge(options) @lookup = @options[:lookup] @mapper = @options[:mapper] @@ -34,6 +30,10 @@ def db protected + def default_options + { :lookup => :id } + end + def with_rescues yield rescue Mongo::GridError, BSON::InvalidObjectId => e diff --git a/lib/rack/gridfs/endpoint/connection.rb b/lib/rack/gridfs/endpoint/connection.rb index 78cf32f..e6dc179 100644 --- a/lib/rack/gridfs/endpoint/connection.rb +++ b/lib/rack/gridfs/endpoint/connection.rb @@ -12,6 +12,13 @@ def initialize(*) @options.values_at(:hostname, :port, :database, :username, :password) end + def default_options + super.merge({ + :hostname => 'localhost', + :port => Mongo::Connection::DEFAULT_PORT + }) + end + def db @db ||= (super || connect!) end