Skip to content

Commit

Permalink
Move connection opts
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarini authored and ches committed Apr 18, 2011
1 parent 133ee5c commit 4da2992
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/rack/gridfs/endpoint/base.rb
Expand Up @@ -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]
Expand All @@ -34,6 +30,10 @@ def db

protected

def default_options
{ :lookup => :id }
end

def with_rescues
yield
rescue Mongo::GridError, BSON::InvalidObjectId => e
Expand Down
7 changes: 7 additions & 0 deletions lib/rack/gridfs/endpoint/connection.rb
Expand Up @@ -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
Expand Down

0 comments on commit 4da2992

Please sign in to comment.