It's common knowledge that ActiveRecord can be used nicely without Rails in Ruby apps. Setting up the basic stuff is pretty easy by just requiring the activerecord gem in your app and defining a couple of models.
But what about migrations, yaml config and different environments? You have to set all this up manually, and even though this is not really hard, it's still a time-consuming task. No more!
I published a new project on GitHub today, called ActiveRecord Skeleton, and it really is just that: It will instantly give you YAML db config, database migrations (including Rake tasks for migrating the database as well as generating new migrations), a Rails-style project directory structure, and also the option of using environments by specifying the RACK_ENV environment variable. Why RACK_ENV? Well, you might also see this as a super-minimalist web app template, allowing you to set up a db-backed Sinatra (just an example, anything should work really) app instantly. All you really got to do is get the skeleton and add an application.rb file containing the following:
require 'sinatra'
require 'init'
get '/' do
User.all.map {|u| u.name}.to_sentence
end
After running application.rb and pointing your browser to localhost:4567, you will see the list of existing users (assuming you've got the database and model set up properly, of course).
Want to create a user? Start irb, do a require 'init' followed by User.create.
This skeleton is really minimalist, as I didn't want it to be over-opinionated. It's meant to give an easy start for about any Ruby code you might want to have database-interaction with and is ready to go with sqlite 3 in the default setup, but you really can use it with any database ActiveRecord supports.
As a consequence of the minimalist approach, the skeleton does not supply tasks or folders for tests. The reason for this is simply that I did not want to force users of the skeleton into using a certain testing library. Test::Unit, Shoulda, RSpec, (your favorite testing framework mentioned here), just pick your favorite and add it your project. This is by no means a suggestion to ditch testing altogether though. You're just supposed to pick your flavour of TDD or BDD.
Now head over to GitHub and give it a spin!
blog comments powered by Disqus