leanback 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Changelog.rdoc ADDED
@@ -0,0 +1,8 @@
1
+ =Leanback 0.2.2
2
+ July 13, 2011:-
3
+ * No need to call add_finder() method directly anymore. find_by() now adds a finder index to the database if one doesn't already exist.
4
+ Example:
5
+ The method:
6
+ Couchdb.find_by( :database => 'contacts', :email => 'nancy@mail.com')
7
+ will add the finder to the database if one doesn't already exist. No need to call
8
+ Couchdb.add_finder(:database => 'contacts', :key => 'email')
data/README.rdoc CHANGED
@@ -77,21 +77,31 @@ Retrieve all documents in a database
77
77
  puts d["phone"]
78
78
  end
79
79
 
80
- ===To Find documents by key
81
- First add a finder/index to the database. Let's say we want to add an index to quickly search the database by an email value.
82
- Couchdb.add_finder(:database => 'contacts', :key => 'email')
83
-
84
- We have just added a find_by_email index to the database.
85
80
 
86
- Now to find documents by email key (example: to find all contacts with email = 'nancy@mail.com')
81
+ ===To Find documents by key
82
+ To find documents by email key (example: to find all contacts with email = 'nancy@mail.com')
87
83
  Couchdb.find_by( :database => 'contacts', :email => 'nancy@mail.com')
88
84
  # => [{"_id"=>"Nancy", "_rev"=>"1-d15a83d2a23b495c19df2595b636ecc8", "firstname"=>"Nancy", "lastname"=>"Lee",
89
85
  "phone"=>"347-808-3734", "email"=>"nancy@mail.com", "gender"=>"female"}]
90
86
 
87
+ To find all contacts with lastname = 'Smith'
88
+ Couchdb.find_by( :database => 'contacts', :lastname => 'Smith')
89
+ # => [{"_id"=>"john", "_rev"=>"5-642689e0a50843d6fa508159a01b4fd4", "firstname"=>"John", "lastname"=>"Smith",
90
+ "email"=>"john@mail.com", "gender"=>"male"}]
91
+
92
+ To find all female contacts
93
+ Couchdb.find_by( :database => 'contacts', :gender => 'female')
94
+ # => [{"_id"=>"Nancy", "_rev"=>"1-d15a83d2a23b495c19df2595b636ecc8", "firstname"=>"Nancy", "lastname"=>"Lee",
95
+ "phone"=>"347-808-3734", "email"=>"nancy@mail.com", "gender"=>"female"}]
96
+
97
+
91
98
  ====How it works
92
99
  The method
93
- Couchdb.add_finder(:database => 'contacts', :key => 'email')
94
- creates a new design document in the contacts database called _design/email_finder with a view called find_by_email
100
+ Couchdb.find_by(:database => 'contacts', :email => 'nancy@mail.com')
101
+ will query the 'contacts' database for a design_document called _design/email_finder and a view called find_by_email with key = "nancy@mail.com".
102
+ It sends a
103
+ GET http://127.0.0.1:5984/contacts/_design/email_finder/_view/find_by_email?key="nancy@mail.com"
104
+ This returns all contacts with email = 'nancy@mail.com'. Leanback will parse the native JSON results to return only the data values. If the design_document and view doesn't exist Leanback will create it in the database. See the source below;
95
105
  {
96
106
  "_id": "_design/email_finder",
97
107
  "_rev": "7-da7f3c0bf183f4a36a82013bd0ea6537",
@@ -106,15 +116,15 @@ creates a new design document in the contacts database called _design/email_find
106
116
  }
107
117
  }
108
118
 
109
- The method
110
- Couchdb.find_by( :database => 'contacts', :email => 'nancy@mail.com')
111
- will query the find_by_email view created above, with a
112
- GET http://127.0.0.1:5984/contacts/_design/email_finder/_view/find_by_email?key="nancy@mail.com"
113
- This returns all contacts with email = 'nancy@mail.com'.
114
- Leanback parses the native JSON results to return only the data values.
119
+ If you ran
120
+ Couchdb.find_by( :database => 'contacts', :lastname => 'Smith')
121
+ Couchdb.find_by( :database => 'contacts', :gender => 'female')
122
+ you will notice the following design_documents have been added to the database
123
+ _design/lastname_finder
124
+ _design/gender_finder
115
125
 
116
126
  ====Usage
117
- You also can do
127
+ You can do
118
128
  docs = Couchdb.find_by( :database => 'contacts', :email => 'nancy@mail.com')
119
129
  docs.each do |d|
120
130
  puts d["_rev"]
@@ -132,8 +142,6 @@ You also can do
132
142
  nancy@mail.com
133
143
  347-808-3734
134
144
 
135
-
136
-
137
145
  ===Query a permanent view
138
146
  view = { :database => "contacts", :design_doc => 'my_views', :view => 'get_female_contacts'}
139
147
  Couchdb.find view
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
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.1"
8
+ s.version = "0.2.2"
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-07-11}
12
+ s.date = %q{2011-07-13}
13
13
  s.description = %q{lightweight Ruby interface to CouchDB}
14
14
  s.email = %q{obioraakubue@yahoo.com}
15
15
  s.extra_rdoc_files = [
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
+ "Changelog.rdoc",
21
22
  "Gemfile",
22
23
  "Gemfile.lock",
23
24
  "LICENSE.txt",
data/lib/leanback.rb CHANGED
@@ -194,7 +194,17 @@ def self.find_by(options)
194
194
  view_name = 'find_by_' + index
195
195
 
196
196
  view = { :database => db_name, :design_doc => design_doc_name, :view => view_name}
197
- find view,search_term
197
+ docs = find view,search_term
198
+
199
+ #add a finder/index if one doesn't already exist in the database
200
+ #then find_by_key
201
+ if(docs.is_a?(Hash))#when finder doesn't exist docs returns {"error"=>"not_found", "reason"=>"missing"}
202
+ if (docs.keys[0].to_s == "error") && (docs.values[0].to_s == "not_found") && (docs.keys[1].to_s == "reason")
203
+ add_finder(:database => db_name, :key => index)
204
+ docs = find view,search_term
205
+ end
206
+ end #end of first if
207
+ return docs
198
208
  end
199
209
 
200
210
  #return a list of all docs in the database
@@ -24,8 +24,10 @@ class TestLeanback < Test::Unit::TestCase
24
24
  end
25
25
 
26
26
  should "find items by key" do
27
- docs = Couchdb.find_by( :database => 'contacts', :email => 'nancy@mail.com')
28
- #puts docs.inspect
27
+ docs = Couchdb.find_by( :database => 'contacts', :email => 'nancy@mail.com')
28
+ #docs = Couchdb.find_by( :database => 'contacts', :lastname => 'Smith')
29
+ #docs = Couchdb.find_by( :database => 'contacts', :gender => 'female')
30
+ puts docs.inspect
29
31
  end
30
32
 
31
33
  should "view document doc" do
@@ -39,7 +41,7 @@ class TestLeanback < Test::Unit::TestCase
39
41
  view = { :database => "contacts", :design_doc => 'more_views', :view => 'get_email'}
40
42
  puts 'viewing design doc...'
41
43
  hash = Couchdb.find view
42
- puts hash.inspect
44
+ #puts hash.inspect
43
45
  end
44
46
 
45
47
  should "Create a design doc/permanent view" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
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-07-11 00:00:00 -04:00
17
+ date: 2011-07-13 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -110,6 +110,7 @@ extra_rdoc_files:
110
110
  - README.rdoc
111
111
  files:
112
112
  - .document
113
+ - Changelog.rdoc
113
114
  - Gemfile
114
115
  - Gemfile.lock
115
116
  - LICENSE.txt
@@ -135,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
136
  requirements:
136
137
  - - ">="
137
138
  - !ruby/object:Gem::Version
138
- hash: 235560335
139
+ hash: -928313619
139
140
  segments:
140
141
  - 0
141
142
  version: "0"