Monk – Quickstart Sinatra Projects
A few coworkers at Citrusbyte (@soveran, @djanowski) have been working on Monk, a new open source web framework. At its core is Sinatra, with a set of bundled technologies to help new projects get moving as quick as possible. It helps you figure out the best structure for your Sinatra app, and gets you moving quickly with logging, settings, and testing.
Monk consists of several components:
Monk Binary
At the core of Monk is a command line tool for starting new projects. Think of the rails command, and what it does and you have a good idea of what the monk command does. It lists, manages and instantiates new skeletons for your project. The Monk binary can instatiate any skeleton you want, which means it is a great way to start projects in any language.
Monk Skeletons
A Monk skeleton is a set of files defining the structure of a new project. There are almost no rules here, the new project can be Sinatra, Django, an ircbot setup, or anything else you want, heck, it could even be Rails.
Monk Default Skeleton
The default Monk skeleton is where lots of work has gone in, and where you’ll find the meat of Monk. It’s a set of amazing tools forming a full-stack Sinatra based web development platform.
- Sinatra - super lightweight web DSL. You know what this is (and if you don’t, go read the rest of this blog, and check it out)
- Ohm - data access layer using Redis, a stupid fast key-value database. Super simple models for your app
- Monk Glue - a Reloader, Logger, and Settings handler for your new application. Don’t worry about it, Sinatra Logging finally made easy… Monk Glue is destined to keep growing too, including a handful of mix & match helpers for common tasks.
- Rack-Test, Contest, Stories, Webrat, Faker, Spawn - An amazing unit and integration test stack, allowing both low level unit tests of your code, and high level integration tests, similar in style to Cucumber, but without that nasty repeating-yourself part. You owe it to yourself to try the stories & webrat approach to testing your Sinatra application.
- Dependencies - trivial management of all the gems you rely on. Just define a dependencies file, and the dependencies gem will handle vendoring and unpacking your requirements.
Monk Glue
Logging - a perennial problem and hassle in setting up new projects is now simple with Monk, and Monk Glue.
get '/' do logger.info("Entered homepage route") "homepage text" end
Reloader - an alternative to the classic Sinatra reloading (with weird require related issues), and Shotgun, which causes a fork() each request, which is fairly heavyweight. Glue’s Reloader is the happy midpoint, between the other two solutions. It reloads everything, but in the same Ruby process, making it much faster.
Settings - a minimalist implementation of the settings.yml file, with environment support. Easily switch up your database settings, your email address, url and more. Bonus Feature: the default skeleton creates an automatic settings.yml file when you first run monk:start.
get '/' do @foobar = settings(:foobar) "the value of the foobar setting is:" + @foobar end
Ohm Persistence Layer
Ohm is a lightweight data management layer that uses Redis as it’s backend. Redis is a fast key-value database, and Ohm makes mappings that are simple to define, and automates the nasty parts of key-value databases like reverse lookups (indexes). Ohm isn’t technically an ORM, since there’s no relational database backing it, but it fills the same niche as ActiveRecord or Datamapper, storing your data for future use.
Awesome Reddit Clone Example
Check out http://news.monkrb.com/, the code is located at http://github.com/monkrb/reddit-clone
Pay attention for a future blog post digging further into this example code, and dissecting it.
Get Monk & Find out More
Install Monk
gem install monk
Links
- Official Monk Website - http://monkrb.com
- Monk Github: http://www.github.com/monkrb/monk
- Monk Default Skeleton Github: http://www.github.com/monkrb/skeleton
- Monk Glue Github: http://www.github.com/monkrb/glue
- Ohm Documentation: http://ohm.keyvalue.org/
- Ohm Github: http://github.com/soveran/ohm
- Monk Mailing List Link: http://groups.google.com/group/monkrb
August 21st, 2009 at 12:30 pm
[…] http://www.gittr.com/index.php/archive/monk-quickstart-sinatra-projects/ […]