Class: CouchRest::Changes::DatabaseProxy
- Inherits:
-
Object
- Object
- CouchRest::Changes::DatabaseProxy
- Defined in:
- lib/couchrest/changes/database_proxy.rb
Overview
CouchRest uses curl for ‘streaming’ requests (requests with a block passed to the db).
Unfortunately, this leaks the username and password in the process list. We don’t want to do this. So, we create two separate CouchRest::Database instances: one that is for normal requests and one that is used for streaming requests. The streaming one we hack to use netrc file in order to keep authentication info out of the process list.
If no netrc file is configure, then this DatabaseProxy just uses the regular db.
Instance Method Summary collapse
- #changes(*args, &block) ⇒ Object
-
#initialize(db_name) ⇒ DatabaseProxy
constructor
A new instance of DatabaseProxy.
Constructor Details
#initialize(db_name) ⇒ DatabaseProxy
Returns a new instance of DatabaseProxy.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/couchrest/changes/database_proxy.rb', line 17 def initialize(db_name) @db = CouchRest.new(Config.couch_host).database(db_name) unless @db Config.logger.error { "Database #{db_name} not found!" } raise RuntimeError "Database #{db_name} not found!" end if Config.connection[:netrc] && !Config.connection[:netrc].empty? @db_stream = CouchRest.new(Config.couch_host_no_auth).database(db_name) streamer = @db_stream.instance_variable_get('@streamer') # cheating, not exposed. streamer.default_curl_opts += " --netrc-file \"#{Config.connection[:netrc]}\"" else @db_stream = @db end end |
Instance Method Details
#changes(*args, &block) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/couchrest/changes/database_proxy.rb', line 32 def changes(*args, &block) if block @db_stream.changes(*args, &block) else @db.changes(*args) end end |