I continue working on couch_design_docs, a gem to load javascript files from the file system into my CouchDB store as design docs.
Creating a gemspec (needed by github) is easy with bones:
cstrom@jaynestown:~/repos/couch_design_docs$ rake gem:specAfter pushing the changes to github and a little wait, I can now install my own gem:
(in /home/cstrom/repos/couch_design_docs)
cstrom@jaynestown:~/repos/couch_design_docs$ git status
# On branch master
# Untracked files:
# (use "git add..." to include in what will be committed)
#
# couch_design_docs.gemspec
cstrom@jaynestown:~$ gem install eee-c-couch_design_docsI could also have installed from my local copy using bones's
WARNING: Installing to ~/.gem since /usr/lib/ruby/gems/1.8 and
/usr/bin aren't both writable.
Successfully installed eee-c-couch_design_docs-1.0.0
1 gem installed
rake gem:install
.With the gem installed, I can take it for a ride:
cstrom@jaynestown:~/repos/eee-code$ irbCool! That was easy enough. To instantiate a
>> require 'couch_design_docs'
=> true
Store
object:>> store = CouchDesignDocs::Store.new("http://localhost:5984/eee")And a local document store:
=> #<CouchDesignDocs::Store:0xb7a07c58 @url="http://localhost:5984/eee">
>> dir = CouchDesignDocs::Directory.new("/home/cstrom/repos/eee-code/couch/_design")Nice! So, can I get the store to upload the design document?
=> #<CouchDesignDocs::Directory:0xb7970948 @couch_view_dir="/home/cstrom/repos/eee-code/couch/_design">
>> dir.to_hash
=> {"lucene"=>{"transform"=>"function(doc) { … }"}}
>> store.load(dir.to_hash)Conflict, bummer. That is something missing from the gem—the ability to replace existing documents. For now, I will manually delete the couchdb-lucene design document:
RestClient::RequestFailed: HTTP status code 409
from /usr/lib/ruby/gems/1.8/gems/rest-client-1.0/lib/restclient/request.rb:193:in `process_result'
from /usr/lib/ruby/gems/1.8/gems/rest-client-1.0/lib/restclient/request.rb:123:in `transmit'
from /usr/lib/ruby/1.8/net/http.rb:543:in `start'
…
With that, I can retry:
>> store.load(dir.to_hash)Yay! The
=> {"lucene"=>{"transform"=>"function(doc) { … }" }}
.js
file from the filesystem was actually PUT
in the CouchDB data store as desired.I spend a little more time with the document store class—driving by example the ability to replace an existing design document. I hope to be able to finish up the gem tomorrow by adding some convenience methods and the ability to replace existing documents.
(commit)
Are you working on a Ruby version of CouchApp (http://groups.google.com/group/couchapp) or is the scope of your project different?
ReplyDeleteI was not planning to do something as encompassing as CouchApp.
ReplyDeleteI am more comfortable using CouchDB as a data store and something else (like Sinatra) as a presentation / application layer. That is what I am looking to accomplish here -- a means to manage the design docs as part of a Sinatra app. I am keeping a eye toward being able to better test the javascript functions and possibly allow for code re-use (via Erb).
Still, from what I have seen of CouchApp, this is very similar. So who knows? Maybe it will evolve into a CouchApp for ruby.