public
Description: Ruby interface to CouchDB
Homepage: http://code.google.com/p/activecouch/
Clone URL: git://github.com/JackDanger/active_couch.git
Search Repo:
Working commit of _id and _rev methods.

git-svn-id: http://activecouch.googlecode.com/svn/trunk@55 
e44de9e2-1e40-0410-bb6c-c9d70e891a3e
chuyeow (author)
Fri Jan 18 02:31:35 -0800 2008
commit  b5921f51bc9228e26f77977973160148b1c9c511
tree    03a54c1a3913a5e0e15f966714aacb7eabec4978
parent  ce1fb6c9370984ed3e6bcb4096b5aecb5eddfaa5
...
1
2
3
4
 
5
6
7
...
28
29
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
32
33
...
1
2
3
 
4
5
6
7
...
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
0
@@ -1,7 +1,7 @@
0
 module ActiveCouch
0
   class Base
0
     SPECIAL_MEMBERS = %w(attributes associations connection)
0
-
0
+
0
     def initialize(params = {})
0
       # Object instance variable
0
       @attributes, @associations, @connection, klass_atts, klass_assocs = {}, {}, self.class.connection, self.class.attributes, self.class.associations
0
@@ -28,6 +28,31 @@ module ActiveCouch
0
       from_hash(params)
0
     end
0
 
0
+ # Returns the "_id" of the CouchDB document represented by this instance.
0
+ def id
0
+ @id ||= attributes[:_id]
0
+ end
0
+
0
+ # Sets the "_id" of the CouchDB document represented by this instance.
0
+ # This doesn't do anything unless this is a new document.
0
+ def id=(new_id)
0
+ if new?
0
+ attributes[:_id] = @id = new_id
0
+ else
0
+ nil
0
+ end
0
+ end
0
+
0
+ # Returns the "_rev" of the CouchDB document represented by this instance.
0
+ def rev
0
+ @rev ||= attributes[:_rev]
0
+ end
0
+
0
+ # Returns true if this is a new CouchDB document.
0
+ def new?
0
+ @rev.nil?
0
+ end
0
+
0
     def to_json
0
       hash = {}
0
       # @attributes and @associations are hashes. Get all
...
26
27
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
30
31
...
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
0
@@ -26,6 +26,37 @@ class Blog < ActiveCouch::Base
0
   has_many :comments
0
 end
0
 
0
+describe "An object instantiated from the subclass of ActiveCouch::Base" do
0
+ before(:each) do
0
+ @person = Person.new
0
+ end
0
+
0
+ it "should have accessors for the id attribute" do
0
+ @person.should respond_to(:id)
0
+ @person.should respond_to(:id=)
0
+ end
0
+
0
+ it "should have a reader for the rev attribute" do
0
+ @person.should respond_to(:rev)
0
+ end
0
+end
0
+
0
+describe "A new ActiveCouch::Base instance" do
0
+ before(:each) do
0
+ @person = Person.new
0
+ end
0
+
0
+ it "should be new" do
0
+ @person.should be_new
0
+ end
0
+
0
+ it "should not be new once it has been saved"
0
+
0
+ it "should allow you to set the id attribute"
0
+
0
+ it "should set the id and rev attributes after being saved"
0
+end
0
+
0
 describe "A class which is a subclass of ActiveCouch::Base" do
0
   before(:each) do
0
     @p = Person.new

Comments

    No one has commented yet.