| | |
Cramp is the latest entry on the ruby web frameworks list. However, unlike all the others, Cramp is an asynchronous framework, always running inside EventMachine reactor loop. Cramp isn’t a good fit for most of the web applications out there. However, Cramp is good at holding and working with a large number of open connections. Hence it’ll work great for things like comet, long polling, streaming API or even when your application needs to handle thousands of concurrent connections. | | |
This article assumes that you’re aware with the evented programming model. If you are not, things below this point might not make much of a sense. If you’re interested in learning, you could start by reading about EventMachine and Twisted. | | |
| | |
As Cramp requires 0.2.0-pre Arel and 3.0-pre versions of ActiveSupport and ActiveModel. So you’ll have to install them first. This step will be irrelevant after Rails 3 gets released. But for now, the following should install them : | | |
| | |
gem install activemodel --pre | | |
| | |
| | |
That’ll install Cramp gem along with all the needed dependencies. Please note that Cramp depends on ActiveSupport 3.0-pre gem, which isn’t backwards compatible and this may affect any other gems requiring ActiveSupport without specifying the version number. | | |
| | |
Cramp comes with two layers : Controller & Model. | | |
| | |
Cramp::Controller is an asynchronous controller layer, that tries being rack compliant as much as possible. Currently, you must use thin or Rainbows! in order to run it. If you’re using Rainbows!, make sure you use EventMachine concurrency model. | | |
Here’s the “hello world” of Cramp::Controller: | | |
| | |
require 'cramp/controller' | | |
class WelcomeAction < Cramp::Controller::Action | class WelcomeAction < Cramp::Controller::Action History of edits
(Latest: Tyz 2 years ago)
§ | |
on_start :send_hello_world | | |
| | |
| | |
| | |
| | |
| | |
Rack::Handler::Thin.run WelcomeAction, :Port => 3000 | Rack::Handler::Thin.run WelcomeAction, :Port => 3000 History of edits
(Latest: Tyz 2 years ago)
§ | |
| | |
| | |
Here WelcomeAction is the rack endpoint, which you can use with config.ru or what have you. | | |