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. 
Name Total lines Lines of code Total coverage Code coverage
lib/couchy/database.rb 129 62
100.0%  
100.0%  
 1
    require 'cgi'  2 require
    'base64'  3  4 module Couchy  5 class Database  6 attr_accessor :server, :name
     7  8 def initialize(server, database_name)
     9 @name = database_name
     10 @server = server
     11 end  12  13 # Gets a list of all the documents available in the
    database  14 #
     15 # @param [Hash]
    params  16 #
     17 # @return [Hash]
    Parsed server response  18
    def documents(params={}) 
    19 server.get("#{name}/_all_docs", params)  20 end  21  22 # Creates a temporary view  23 #  24 # @param [String] function The
    view function  25 #
    @param [Hash] params  26
    #  27 # @return [Hash]
    Parsed server response  28
    def temp_view(function, params={})  29 server.post("#{name}/_temp_view", function,
     30
    params.merge!(:headers => {'Content-Type' => 'application/json'}))
     31 end  32  33 # Query a view  34 # 
    35 # @param [String] view_name The name of the view  36 # @param [Hash] params
     37 #  38 # @return [Hash] Parsed server
    response  39 def
    view(view_name, params={})  40 server.get("#{name}/_view/#{view_name}",
    params)  41 end
     42  43 # Retrieves a document by its ID
     44 #  45 # @param [String] id The ID of
    the document  46 #
     47 # @return [Hash]
    Parsed server response  48
    def get(id)  49
    server.get("#{name}/#{CGI.escape(id)}")  50 end  51  52 # Retrieves an attachment from a document  53 #  54 # @param [String] document_id The
    ID of the document  55 #
    @param [String] attachment_name The name of the attachment  56 #  57 # @return [Hash] Parsed server
    response  58 def
    fetch_attachment(document_id, attachment_name)  59
    server.get("#{name}/#{CGI.escape(document_id)}/#{CGI.escape(attachment_
    ame)}", :no_json => true)  60 end  61 
    62 # Saves or updates a document  63 # 
    64 # @param [Hash] doc The document  65 # 
    66 # @return [Hash] Parsed server response  67 def save(doc)  68 doc = encode_attachments_of(doc)  69  70 if doc['_id']  71
    server.put("#{name}/#{CGI.escape(doc['_id'])}", doc)  72 else  73 server.post("#{name}",
    doc)  74 end
     75 end  76  77 # Saves or updates a bunch of documents  78 #  79 # @param [Array] docs The
    documents to save  80 #
     81 # @return [Hash]
    Parsed server response  82
    def bulk_save(docs)  83
    server.post("#{name}/_bulk_docs", {:docs => docs})  84 end  85  86 # Deletes a document  87 # 
    88 # @param [String, Hash] document Document ID or an Hash representing the
    document  89 # @param
    [String] revision Document's revision  90 # 
    91 # @raise ArgumentError When the Hash representing the document neither
    has  92 # an ID nor a
    revision  93 #
     94 # @raise
    ArgumentError When document is neither an ID nor an Hash  95 # representing a document
     96 #  97 # @return [Hash] Parsed server
    response  98 def
    delete(document, revision=nil)  99 case document 100 when String 101 raise ArgumentError, 'Document revision must be
    specified' unless revision 102 server.delete
    "#{name}/#{CGI.escape(document)}", :rev => revision
    103 when Hash
    104 raise ArgumentError,
    'Document ID and revision must be specified' unless 105 document['_id'] &&
    document['_rev'] 106
    server.delete("#{name}/#{CGI.escape(document['_id'])}", :rev =>
    document['_rev']) 107
    else 108 raise
    ArgumentError, 'Document must be an Hash representing the document or its
    ID' 109 end
    110 end 111 112 # Deletes the current database
    113 # 114 # @return [Hash] Parsed server
    response 115 def delete!
    116 server.delete(name)
    117 end 118 119 private 120 def encode_attachments_of(doc) 121 return doc unless
    doc['_attachments'] 122
    doc['_attachments'].each { |_, v| v.update('data' => base64(v['data'])) }
    and doc 123 end
    124 125 def base64(data) 126
    Base64.encode64(data.to_s).gsub(/\s/,'') 127 end 128 end 129 end 

Generated using the rcov code coverage analysis tool for Ruby version 0.8.1.2.

Valid XHTML 1.0! Valid CSS!