C0 code coverage information
Generated on Sat Oct 11 12:39:45 +0200 2008 with
rcov 0.8.1.2
Code reported as executed by Ruby looks like
this... and this: this line is also marked as
covered. Lines considered as run by rcov, but
not reported by Ruby, look like this, and
this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not
executed.
1
module Couchy 2 class
Server 3 attr_accessor
:uri 4 5 def initialize(uri) 6 @uri = Addressable::URI.parse(uri)
7 end 8 9 # Gets information about the server 10 # 11 # @return [Hash] Parsed server
response 12 def info
13 get '/' 14 end 15 16 # Restarts the server 17 # 18 # @return [Hash] Parsed server response 19 def restart! 20 post '_restart' 21 end 22 23 # Gets a list of all the databases available on the
server 24 # 25 # @return [Array] Parsed server
response 26 def databases
27 get '_all_dbs'
28 end 29 30 # Gets a new [Couchy::Database] for the database
31 # 32 # @param [String] name The name of
the database 33 #
34 # @return
[Couchy::Database] The database 35 def database(name) 36 Database.new(self, name) 37 end 38 39 # Creates a database 40 # 41 # @param [String] name Database's name 42 # 43 # @return [Couchy::Database] The
newly created database 44
def create_db(name) 45
put(name) 46
database(name) 47 end
48 49 def get(path, params={})
50 need_json =
!params.delete(:no_json) 51 response = RestClient.get(uri_for(path, params))
52 need_json ?
json(response, :max_nesting => false) : response 53 end 54 55 def post(path, doc=nil, params={}) 56 headers = params.delete(:headers)
57 payload = doc.to_json
if doc 58 json
RestClient.post(uri_for(path, params), payload, headers) 59 end 60 61 def put(path, doc=nil) 62 payload = doc.to_json if doc 63 json RestClient.put(uri_for(path),
payload) 64 end
65 66 def delete(path, params={})
67 json
RestClient.delete(uri_for(path, params)) 68 end 69 70
private 71 def
uri_for(path, params={}) 72 u = uri.join(path) 73 u.query_values =
stringify_keys_and_jsonify_values(params) if params.any? 74 u.to_s 75 end 76 77 def json(json_string, options={}) 78 JSON.parse(json_string, options)
79 end 80 81 def stringify_keys_and_jsonify_values(hash)
82 hash.inject({}) do
|memo, (key, value)| 83
value = value.to_json if %w(key startkey endkey).include?(key.to_s)
84 memo[key.to_s] =
value.to_s 85 memo
86 end 87 end 88 end 89 end
Generated using the rcov
code coverage analysis tool for Ruby version 0.8.1.2.