leanback 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog.rdoc CHANGED
@@ -1,6 +1,14 @@
1
+ =Leanback 0.2.6
2
+ August 3, 2011:-
3
+ * Added ability to delete documents without having to retrieve the _rev revision number
4
+ Example:
5
+ doc = {:database => 'contacts', :doc_id => 'James'}
6
+ Document.delete doc
7
+ The above will delete the document with id 'james'. See README for details.
8
+
1
9
  =Leanback 0.2.5
2
10
  August 2, 2011:-
3
- * Added dynamic updates for documents. This makes it easy to update documents without deleting old fields or having to track the _rev value.
11
+ * Added dynamic updates for documents. This makes it easy to update documents without deleting old fields or having to track the _rev number.
4
12
  To update a document now:
5
13
  data = {"age" => "53" }
6
14
  doc = { :database => 'contacts', :doc_id => 'john', :data => data}
@@ -15,12 +23,12 @@ July 20, 2011:-
15
23
  July 19, 2011:-
16
24
  * Added better error handling all database operations now raise a CouchdbException when something goes wrong. It's now easy to track exceptions.
17
25
 
18
- begin
19
- Couchdb.create 'contacts'
20
- rescue => e
21
- puts "Error message: " + e.to_s
22
- puts "Error value: " + e.error
23
- end
26
+ begin
27
+ Couchdb.create 'contacts'
28
+ rescue => e
29
+ puts "Error message: " + e.to_s
30
+ puts "Error value: " + e.error
31
+ end
24
32
  # => Error message: CouchDB: Error - file_exists. Reason - The database could not be created, the file already exists.
25
33
  Error value: file_exists
26
34
 
data/README.rdoc CHANGED
@@ -48,25 +48,25 @@ Create a new document
48
48
  This will create a new document in the 'contacts' database, with document id 'Linda'.
49
49
 
50
50
  Let's update that document to change the email address
51
- data = {"email" => "linda@mail.com" }
51
+ data = {:email => "linda@mail.com" }
52
52
  doc = { :database => 'contacts', :doc_id => 'Linda', :data => data}
53
53
  Document.update doc
54
54
 
55
55
  Let's add gender and age
56
- data = {"age" => "32","gender" => "female" }
56
+ data = {:age => "32", :gender => "female" }
57
57
  doc = { :database => 'contacts', :doc_id => 'Linda', :data => data}
58
58
  Document.update doc
59
59
 
60
60
 
61
61
  To change phone# and add a fax number
62
- data = {"phone" => "718-234-2904","fax" => "646-309-4049" }
62
+ data = {:phone => "718-234-2904",:fax => "646-309-4049" }
63
63
  doc = { :database => 'contacts', :doc_id => 'Linda', :data => data}
64
64
  Document.update doc
65
65
 
66
66
  Let's add twitter account, facebook account and website url
67
- data = {"twitter" => "http://twitter.com/#!/linda",
68
- "faceboook" => "http://facebook.com/linda",
69
- "website" => "http://linda-blogs.com" }
67
+ data = { :twitter => "http://twitter.com/#!/linda",
68
+ :faceboook => "http://facebook.com/linda",
69
+ :website => "http://linda-blogs.com" }
70
70
 
71
71
  doc = { :database => 'contacts', :doc_id => 'Linda', :data => data}
72
72
  Document.update doc
@@ -92,7 +92,7 @@ To edit the document and replace it with a new one
92
92
  Document.edit doc
93
93
 
94
94
  # => {"ok"=>true, "id"=>"Linda", "rev"=>"6-211ebb68bdd4ba8799387214b4a3b445"}
95
- This replaces the existing document with a new one, the _rev property must be included in the data.
95
+ This replaces the existing document with a new one, the _rev number of the document must be included in the data.
96
96
 
97
97
  Retrieve/view the document
98
98
  doc = {:database => 'contacts', :doc_id => 'Linda'}
@@ -102,10 +102,16 @@ Retrieve/view the document
102
102
  "lastname"=>"smith", "email"=>"linda@mail.com", "gender"=>"female", "phone"=>"718-245-5611"}
103
103
 
104
104
  Delete the document
105
+ doc = {:database => 'contacts', :doc_id => 'Linda'}
106
+ Document.delete doc
107
+
108
+ #=> {"ok"=>true, "id"=>"Linda", "rev"=>"7-a2cfbbb607a668c26256bc19ff270ecf"}
109
+
110
+ Delete the document using it's revision number (_rev):
105
111
  doc = {:database => 'contacts', :doc_id => 'Linda', :rev => '2-e813a0e902e3ac114400ff3959a2adde'}
106
- Document.delete doc
112
+ Document.delete_rev doc
107
113
 
108
- # => {"ok"=>true, "id"=>"Linda", "rev"=>"3-48580d1806983b32cb03f114efb064e3"}
114
+ #=> {"ok"=>true, "id"=>"Linda", "rev"=>"3-48580d1806983b32cb03f114efb064e3"}
109
115
 
110
116
  Retrieve all documents in a database
111
117
  docs = Couchdb.docs_from 'contacts'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
data/leanback.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{leanback}
8
- s.version = "0.2.5"
8
+ s.version = "0.2.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Obi Akubue"]
12
- s.date = %q{2011-08-03}
12
+ s.date = %q{2011-08-04}
13
13
  s.description = %q{lightweight Ruby interface to CouchDB}
14
14
  s.email = %q{obioraakubue@yahoo.com}
15
15
  s.extra_rdoc_files = [
data/lib/leanback.rb CHANGED
@@ -56,8 +56,19 @@ module Document
56
56
  edit doc
57
57
  end
58
58
 
59
- #delete a doc
60
- def self.delete(doc)
59
+ #delete document
60
+ def self.delete(doc)
61
+ db_name = doc[:database]
62
+ doc_id = doc[:doc_id]
63
+ doc = {:database => db_name, :doc_id => doc_id}
64
+ hash = Couchdb.view doc
65
+ doc = {:database => db_name, :doc_id => doc_id, :rev => hash["_rev"]}
66
+ delete_rev doc
67
+ end
68
+
69
+
70
+ #delete a doc by rev#
71
+ def self.delete_rev(doc)
61
72
  db_name = doc[:database]
62
73
  doc_id = doc[:doc_id]
63
74
  rev = doc[:rev]
@@ -119,7 +119,7 @@ class TestLeanback < Test::Unit::TestCase
119
119
 
120
120
  should "update the document" do
121
121
  #data = {"age" => "42", "lastname" => "arnold", "phone" => "202-456-1234", "hobbies" => "football,running, video gamess" }
122
- data = {"age" => "13" }
122
+ data = {"age" => "54" }
123
123
  doc = { :database => 'contacts', :doc_id => 'john', :data => data}
124
124
  Document.update doc
125
125
  end
@@ -136,10 +136,30 @@ class TestLeanback < Test::Unit::TestCase
136
136
  end
137
137
  end
138
138
 
139
- should "delete a document - handle exceptions" do
140
- begin
141
- doc = {:database => 'contacts', :doc_id => 'john', :rev => '3-be02e80490f8e9e610d9a9e33d752316'}
139
+ should "create and delete a document -- any handle exceptions" do
140
+ begin
141
+
142
+ data = {:firstname => 'James',
143
+ :lastname =>'Nova',
144
+ :phone => '212-234-1234',
145
+ :email =>'james@mail.com'}
146
+
147
+ doc = {:database => 'contacts', :doc_id => 'james', :data => data}
148
+ Document.create doc
149
+
150
+ doc = {:database => 'contacts', :doc_id => 'James'}
142
151
  hash = Document.delete doc
152
+ puts hash.inspect
153
+ rescue CouchdbException => e
154
+ #puts e.to_s
155
+ #puts e.error
156
+ end
157
+ end
158
+
159
+ should "delete a document with revision number - any handle exceptions" do
160
+ begin
161
+ doc = {:database => 'contacts', :doc_id => 'james', :rev => '4-4e70528f7400e2e43d6543aec4d8aa2b'}
162
+ hash = Document.delete_rev doc
143
163
  #puts hash.inspect
144
164
  rescue CouchdbException => e
145
165
  #puts e.to_s
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 5
9
- version: 0.2.5
8
+ - 6
9
+ version: 0.2.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Obi Akubue
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-08-03 00:00:00 -04:00
17
+ date: 2011-08-04 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -136,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
136
  requirements:
137
137
  - - ">="
138
138
  - !ruby/object:Gem::Version
139
- hash: 541704349
139
+ hash: -85195711
140
140
  segments:
141
141
  - 0
142
142
  version: "0"