RUBY LANGUAGE CENTER
Using Ruby on 10gen
10gen now supports Ruby. Babble, the 10gen application server, can deploy and run applications written in Ruby, as well as web applications developed using the Rails framework. Ruby and Rails can be adapted to work seamlessly with Mongo, GridFS, and the other components of the 10gen cloud. Just as Rails allows the developer to focus on logic and information by taking care of the small details of an application's infrastructure, 10gen goes a step further by taking care of the details of the application's deployment, scalability and availability.This page is a starting point for developers who want more information about developing applications in Ruby (on or off Rails) for deployment on the 10gen cloud.
Overview
The general descriptions in this section are enlarged upon in the sections that follow.- Support for Ruby
Babble, 10gen's application server, supports the Ruby programming language through JRuby. In addition, Babble further supports the Ruby developer by creating Ruby-accessible objects ($session,$db, etc.) that represent the basic components of the 10gen cloud.
Similarly, Babble automatically brings objects written in other languages into the Ruby environment.
See Language Support for more details. - Support for Rails
10gen provides configuration files that adapt Rails facilities for logging, session management, routing, etc. to work with the 10gen infrastructure. Once these files are created in specific directories within the Rails structure, Babble will run a Rails application with no further adaptation.
See Development Support for details. - Support for ActiveRecord
10gen support for ActiveRecord is still in development. But 10gen also includes ActiveRecord-like classes that work with or without Rails to persist Ruby objects to Mongo. In any case, any Ruby code running on Babble can always interact with Mongo directly.
See Database Support for details.
Language Support
Babble creates a number of objects for use in a Ruby application. Some examples:$scope | the runtime environment |
$db | the database (see Database Support for more information) |
$session | the session object |
$stderr, | give Ruby access to Babble's input and output streams |
In addition, 10gen defines classes like the following classes to be instantiated as needed:
GridFile | represents files that are stored in GridFS |
XGen::Mongo::Base andXGen::Mongo::Cursor | database-related—see Database Support for more information |
XGen::Mongo::Session | for session persistence to the database |
XGen::Mongo::LogDevice | can be used to store log messages in the database |
See The Ruby on 10gen RDocs page for reference documentation of 10gen-related files, classes and methods.
Support for other languages
10gen has modified Ruby'srequire and load utilities to work better with Babble's multi-language capabilities: if the 10gen versions don't find Ruby implementations of the requested files, they search for versions in other languages.
See the README.rdoc file for details of how Babble creates Ruby objects based on code written in other languages.
Differences to Watch For
- Threading
To maintain control of resources in a shared environment, Babble does not allow the creation of Ruby threads. UseXGen::BabbleThreadto do this.
Development Support
The 10gen platform supports Rails, a major development framework for Ruby. The application structures generated by Rails work just as well for cloud-based applications as they do for web-based applications. You can set up Rails to run on Babble by placing two standard 10gen files at specific places in the Rails directory structure.
See Also:
See the README file or this wiki page for step-by-step instructions for "Babble-ifying" a Rails application.
Database Support
The current version of Babble does not support ActiveRecord. 10gen's goal is to enable ActiveRecord to connect a Ruby/Rails application to Mongo just it readily as it connects a Rails application to an SQL database. Until 10gen reaches this goal, the Ruby programmer can connect to Mongo in either of two ways:- Use
XGen::Mongo::Base, a module that provides many ActiveRecord-style interfaces between Ruby and Mongo. See The Ruby on 10gen RDocs page for reference information aboutXGen::Mongo::Base. - Talk to Mongo directly using the
$dbobject.
Differences to Watch For
ActiveRecord support is not finalized, but it is on the way.
See Also:
10gen's Mongo Database User's Guide devotes a special section to linking Mongo to Ruby. (The tutorial as a whole is a useful introduction to Mongo.)There are two native Ruby drivers for Mongo available from external sources:
Examples
The 10gen installation provides the following examples of Ruby applications written for deployment on the 10gen cloud:
- Hello World -- a simple example. See http://www.10gen.com/wiki/DevTutorial010_rb for documentation of this example.
- SampleSite -- a more complex example with database interaction and routing. See http://www.10gen.com/wiki/DevTutorial010_rb for documentation of this example.
Documentation
The following Ruby-related documentation can be found in 10gen's documentation wiki:
Example Guides
Hello world example
Tutorials / HowTo pages
How to Babble-ify a Rails Application
Reference Guides
The Ruby on 10gen RDocs page
Component Documentation
"Working with (Ruby) Objects and Classes" from the Mongo Database User's Guide
Ruby-related Posts to the 10gen Group
Installation Problem on Windows
Related Documentation
- The main starting point for 10gen developer documentation
- A page of more 10gen Samples including more Ruby samples
Questions? Comments?
As always, we're happy to help and answer questions - try us on the maillist/forum.
