Getting started with Sinatra, CouchDB & CouchRest? - ruby

I'm just starting to learn my way around CouchDB and Sinatra, but am struggling to find some basic examples of integrating the two via CouchRest. The CouchRest docs assume a little too much to be useful to me yet.
Does anyone have links to useful examples/articles/docs?

Sinatra docs are pretty great and easy to work with.
The examples in the couchrest repo seem to show a lot of use cases. https://github.com/couchrest/couchrest_model
The best way to understand code (and especially bleeding edge ruby) is to just read the code.
Updated, with link to tutorial: http://japhr.blogspot.com/2009/03/spike-sinatra-and-couchdb.html

You should probably look into the couch_potato library too, it just hits the sweet spot between the basic approach of couch rest and active record. Source and examples: https://github.com/langalex/couch_potato

Related

Are there any web frameworks on top of EventMachine?

Are there any web frameworks on top of EventMachine? So far, I've found Fastr and Cramp. Both seem to be outdated.
Moreover, Googling how to setup Rails + EventMachine, returns a limited amount of results.
NodeJS is really nothing new. Evented I/O has been around for a very long time (Twisted for Python and EventMachine for Ruby). However, what attracts me to NodeJS, is the implementations that are built on top of it.
For example. NodeJS has TowerJS. Among plenty others. Perhaps, this is one of the many contributing reasons to its trending factor.
What I like most about TowerJS, is its Rails-like structure. Is there anything like it for EventMachine?
Goliath is an open source version of the non-blocking (asynchronous) Ruby web server framework.
You may find async sinatra interesting
Besides EventMachine and the others mentioned here, there's vert.x. I'm not sure how much of a "web framework" it is, but its site shows examples for a simple app like one might write in Sinatra.

Simple pagination in redis using ohm ruby library

Hi guys I am trying to learn the sinatra framework and would like to use it as the backend for simple web services. I am also attempting to get my hands dirty with no-sequel solutions and for some reasons decided to learn to work with redis. As for the ruby library to be used I have selected Ohm since it seems like a minimal, no fuss library that I could easily use.
However, looking around and researching, I cannot find sample implementation where there is pagination for Ohm. I have also read a bit and redis and I know that you can specify ranges in the query. The question is, how do I use this with the Ohm ruby library?
Any help or any guide would be greatly appreciated.
Last time I wanted that combination I found this here: https://github.com/sinefunc/pagination
Otherwise use https://github.com/mislav/will_paginate whcih will not work with ohm though but you can use datamapper with redis.
If you want to use mongodb you could use mongomapper which has pagination built in but then that is a completely different situation.

'River of news' code sample in ruby?

Looking for a good example of a 'River of News' implementation done in Ruby. Rails, merb, sinatra or any other web framework would work. I have a couple ideas about how to implement it, but would love to see how people would do it.
The implementation should load more items into the same page as soon the user reach the bottom of the document.
For more information about the 'River of News' format, please check this video about humanized reader at vimeo.
I know about Mars, a river-of-news aggregator written by Sam Ruby as a port of Venus (which is written in Python and is a refactoring of Planet). Please note that, however, it doesn't use a web framework; if this is a strict requirement on your part, then Mars may not be what you need.
Venus, the aggregator which the Mars port has originated from, comes with extensive documentation: some (most?) of it should probably be valid for Mars, too; you may be particularly interested in the architectural diagram of the software.

What are scenarios in which one would use Sinatra or Merb?

I am learning Rails and have very little idea about Sinatra & Merb. I was wondering are the situations where you would use Merb/Sinatra.
Thanks for your feedback!
Sinatra is a much smaller, lighter weight framework than Rails. It is used if you want to get something up running quickly that just dispatches off of a few URLs and returns some simple content. Take a look at the Sinatra home page; that is all you need to get a "Hello, World" up and running, while in Rails you would need to generate a whole project structure, set up a controller and a view, set up routing, and so on (I haven't written a Rails app in a while, so I don't know exactly how many steps "Hello, World" is, but its certainly more than Sinatra). Sinatra also has far fewer dependencies than Rails, so it's easier to install and run.
We are using Sinatra as a quick test web server for some web client libraries that we're writing now. The fact that we can write one single file and include all of our logic in that one file, and have very few dependencies, means it's a lot easier to work with and run our tests than if you had a Rails app.
Merb is being merged into Rails, so pretty soon there shouldn't really be any reason to use one over the other. It was originally designed to be a bit lighter weight and more decoupled than Rails; Rails had more built in assumptions that you would use ActiveRecord. But as they are merging the two, they are decoupling Rails in similar ways, so if you're already learning Rails, then it's probably worth it to just stick with that and follow the developments as they come.
I can't speak much for Merb, but Sinatra is highly effective for small or lightweight solutions. If you aren't working with a whole lot of code, or don't need a huge website, you can code a very effective site with Sinatra either as fast, or twice as fast as on Rails (in my own opinion).
Sinatra is also excellent for fragmentary pieces of an application, for instance the front-end to a statistics package. Or something like ErrCount, which is just a really simple hit counter.
So think about light, fast, and highly simplistic web applications (though complexity is your choice) when using Sinatra.
The way things are going, it's going to be a moot question soon.
As mentioned already, Merb 2.0 and Rails 3.0 are going to be the same thing. The newly-combined Merb and Rails core teams are already at work on achieving that. I don't know if they're still planning on a release (probably a beta) by RailsConf in May, but it's definitely happening this year.
If you're dead set on using an ORM other than ActiveRecord, for example, you might start with Merb now and update when 2.0 (Rails 3.0) ships. Right now, Merb is generally accepted to provide a better framework for varying one's components than Rails.
Sinatra looks like a brilliant solution for a web app that has low interface complexity and somewhat lower model-level code than would be normal for Merb/Rails. Implementing straightforward RESTful APIs would be one great use. I'm less convinced about its value when any quantity of HTML is involved, even less so when templating gets involved.
Again, with Rails (and hence Merb soon) now sitting on top of Rack, there's no reason not to include baby Sinatra apps into the solution: they can live together. There's a blog post that discusses that very concept

Client side http proxy in ruby

What is a good approach to a client proxy written in ruby that I can use to create a custom filter.
So far I've found
Ruby Proxy using webrick
Mousehole, a scriptable Ruby proxy by _why (UPDATE this was not robust)
A little on the fringe, this guy wants to Use rack as thin proxy with his question. I don't think he got an answer; or even a hint that it was possible.
What is your advice on these suggested approaches or do you have a better approach.
Thanks!
I can’t speak on personal experience as I’ve not done this myself, but I have heard of mouseHole before and it seems to be a good package. Why not try writing a simple script for it and see how you find it?
There are also some sample scripts in that repository that you could check out.

Resources