Module: Aqua::Store::CouchDB

CouchDB

Public Visibility

Public Class Method Summary

clear_servers

Clears the cached servers.

escape(str)

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.

Returns: String

http_adapter

Returns a string describing the http adapter in use, or loads the default and returns a similar string.

Returns: String

method_missing(method, *args)
paramify_url(url, params = {})

TEXT HELPERS ================================================ This comes from the CouchRest Library and its licence applies.

server(namespace = nil)

Reader for getting or initializtion and getting a server by namespace.

servers

Cache of CouchDB Servers used by Aqua.

set_http_adapter(mod_string = 'RestClientAdapter')

Sets a class variable with the library name that will be loaded.

Returns: String

Public Class Method Details

clear_servers

public clear_servers

Clears the cached servers. So far this is most useful for testing. API will depend on usefulness outside this.

Meta Tags

[View source]


80
81
82
# File 'lib/aqua/store/couch_db/couch_db.rb', line 80

def self.clear_servers
  @servers = {}
end

escape

public String escape(str)

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

Meta Tags

Returns:

[String]

converted

[View source]


113
114
115
116
117
# File 'lib/aqua/store/couch_db/couch_db.rb', line 113

def self.escape( str )
  str.gsub!('::', '__')
  str.gsub!(/[^a-z0-9\-_]/, '')
  str
end

http_adapter

public String http_adapter

Returns a string describing the http adapter in use, or loads the default and returns a similar string

Meta Tags

Returns:

[String]

A string identifier for the HTTP adapter in use

[View source]


18
19
20
# File 'lib/aqua/store/couch_db/couch_db.rb', line 18

def self.http_adapter
  @adapter ||= set_http_adapter
end

method_missing

public method_missing(method, *args)
[View source]


137
138
139
140
141
142
143
144
# File 'lib/aqua/store/couch_db/couch_db.rb', line 137

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

public paramify_url(url, params = {})

TEXT HELPERS ================================================ 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.

Meta Tags

[View source]


94
95
96
97
98
99
100
101
102
103
# File 'lib/aqua/store/couch_db/couch_db.rb', line 94

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

public server(namespace = nil)

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.

Meta Tags

[View source]


68
69
70
71
72
73
74
# File 'lib/aqua/store/couch_db/couch_db.rb', line 68

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

public servers

Cache of CouchDB Servers used by Aqua. Each is identified by its namespace.

Meta Tags

[View source]


58
59
60
# File 'lib/aqua/store/couch_db/couch_db.rb', line 58

def self.servers
  @servers ||= {}
end

set_http_adapter

public String set_http_adapter(mod_string = 'RestClientAdapter')

Sets a class variable with the library name that will be loaded. Then attempts to load said library from the adapter directory. It is extended into the HttpAbstraction module. Then the RestAPI which references the HttpAbstraction module is loaded/extended into Aqua this makes available Aqua.get ‘http:://someaddress.com’ and other requests 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.

Meta Tags

Returns:

[String]

Name of HTTP Client Adapter module

[View source]


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/aqua/store/couch_db/couch_db.rb', line 37

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
Generated on Thursday, August 27 2009 at 05:50:23 PM by YARD 0.2.3.5 (ruby-1.8.6).