Module: Aqua::Store::CouchDB
- Defined in:
- lib/aqua/store/couch_db/server.rb,
lib/aqua/store/couch_db/couch_db.rb,
lib/aqua/store/couch_db/database.rb,
lib/aqua/store/couch_db/result_set.rb,
lib/aqua/store/couch_db/attachments.rb,
lib/aqua/store/couch_db/design_document.rb,
lib/aqua/store/couch_db/storage_methods.rb
Defined Under Namespace
Modules: StorageMethods Classes: Attachments, Conflict, Database, DesignDocument, RequestFailed, RequestTimeout, ResourceNotFound, ResultSet, Server, ServerBrokeConnection
Class Method Summary collapse
-
.clear_servers ⇒ Object
private
Clears the cached servers.
-
.escape(str) ⇒ String
private
- A convenience method for escaping a string, namespaced classes with
-
notation will be converted to __ all other non-alpha numeric characters besides hyphens and underscores are removed.
-
.http_adapter ⇒ String
Returns a string describing the http adapter in use, or loads the default and returns a similar string.
- .method_missing(method, *args) ⇒ Object
-
.paramify_url(url, params = {}) ⇒ Object
This comes from the CouchRest Library and its licence applies.
-
.server(namespace = nil) ⇒ Object
private
Reader for getting or initializtion and getting a server by namespace.
-
.servers ⇒ Object
private
Cache of CouchDB Servers used by Aqua.
-
.set_http_adapter(mod_string = 'RestClientAdapter') ⇒ String
Loads an http_adapter from the internal http_client libraries.
Class Method Details
.clear_servers ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Clears the cached servers. So far this is most useful for testing. API will depend on usefulness outside this.
83 84 85 |
# File 'lib/aqua/store/couch_db/couch_db.rb', line 83 def self.clear_servers @servers = {} end |
.escape(str) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
A convenience method for escaping a string,
- namespaced classes with
-
notation will be converted to __
all other non-alpha numeric characters besides hyphens and underscores are removed
116 117 118 119 120 |
# File 'lib/aqua/store/couch_db/couch_db.rb', line 116 def self.escape( str ) str.gsub!('::', '__') str.gsub!(/[^a-z0-9\-_]/, '') str end |
.http_adapter ⇒ String
Returns a string describing the http adapter in use, or loads the default and returns a similar string
21 22 23 |
# File 'lib/aqua/store/couch_db/couch_db.rb', line 21 def self.http_adapter @adapter ||= set_http_adapter end |
.method_missing(method, *args) ⇒ Object
140 141 142 143 144 145 146 147 |
# File 'lib/aqua/store/couch_db/couch_db.rb', line 140 def method_missing( method, *args ) if @adapter.nil? set_http_adapter # loads up the adapter related stuff send( method.to_sym, eval(args.map{|value| "'#{value}'"}.join(', ')) ) else raise NoMethodError end end |
.paramify_url(url, params = {}) ⇒ Object
This comes from the CouchRest Library and its licence applies. It is included in this library as LICENCE_COUCHREST. The method breaks the parameters into a url query string.
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/aqua/store/couch_db/couch_db.rb', line 97 def self.paramify_url( url, params = {} ) if params && !params.empty? query = params.collect do |k,v| v = v.to_json if %w{key startkey endkey}.include?(k.to_s) "#{k}=#{CGI.escape(v.to_s)}" end.join("&") url = "#{url}?#{query}" end url end |
.server(namespace = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reader for getting or initializtion and getting a server by namespace. Used by various parts of store to define storage strategies. Also conserves memory so that there is only one instance of a Server per namespace.
71 72 73 74 75 76 77 |
# File 'lib/aqua/store/couch_db/couch_db.rb', line 71 def self.server( namespace=nil ) namespace ||= :aqua namespace = namespace.to_sym unless namespace.class == Symbol s = servers[ namespace ] s = servers[namespace.to_sym] = Server.new( :namespace => namespace ) unless s s end |
.servers ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Cache of CouchDB Servers used by Aqua. Each is identified by its namespace.
61 62 63 |
# File 'lib/aqua/store/couch_db/couch_db.rb', line 61 def self.servers @servers ||= {} end |
.set_http_adapter(mod_string = 'RestClientAdapter') ⇒ String
Loads an http_adapter from the internal http_client libraries. Right now there is only the RestClient Adapter. Other adapters will be added when people get motivated to write and submit them. By default the RestClientAdapter is used, and if the CouchDB module is used without prior configuration it is automatically loaded.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/aqua/store/couch_db/couch_db.rb', line 40 def self.set_http_adapter( mod_string='RestClientAdapter' ) # what is happening here: # strips the Adapter portion of the module name to get at the client name # convention over configurationing to get the file name as it relates to files in http_client/adapter # require the hopefully found file # modify the RestAPI class to extend the Rest methods from the adapter # add the RestAPI to Aqua for easy access throughout the library @adapter = mod_string mod = @adapter.gsub(/Adapter/, '') file = mod.underscore require File.dirname(__FILE__) + "/http_client/adapter/#{file}" RestAPI.adapter = "#{mod_string}".constantize extend(::RestAPI) @adapter # return the adapter end |