TODO and some rdocs
[couchobject.git] / README.txt
blob011f1cebf71e63066975415ceec8be0082768baf
1 CouchObject
2 ===========
4 CouchObject is a set of classes to help you talk to CouchDb (http://couchdbwiki.com/) with Ruby.
6     class Bike
7       include CouchObject::Persistable
9       def initialize(wheels)
10         @wheels = wheels
11       end
12       attr_accessor :wheels
14       def to_couch
15         {:wheels => @wheels}
16       end
18       def self.from_couch(attributes)
19         new(attributes["wheels"])
20       end
21     end
23 By including the CouchObject::Persistable and defining two methods on our class we specify how we should serialize and deserialize our object to and from a CouchDb:
25     >> bike_4wd = Bike.new(4)
26     => #<Bike:0x6a0a68 @wheels=4>
27     >> bike_4wd.save("couchobject")
28     => {"_rev"=>1745167971, "_id"=>"6FA2AFB623A93E0E77DEAAF59BB02565", "ok"=>true}
29     >> bike = Bike.get_by_id("couchobject", bike_4wd.id)
30     => #<Bike:0x64846c @wheels=4>
31