Stonemind WEB “Headless” Rails?

“Headless” Rails?

So, I’m sitting here learning Ruby and Rails, and a thought starts to emerge: I wonder if I could use things like ActiveRecord separate from Rails for writing command line database maintenance scripts in Ruby, for example? Then I start to see other Rails features that also might be very useful outside of a Web application, and then I start wondering if Rails could be used not just as a Web application framework, but as a general application framework, in the way that some people have used (or at least suggested using) Struts and Spring in the Java world.

In the past few years, I have been doing a lot of back-end programming in Java that is heavy on file manipulation as well as database and XML processing, often involving complex workflows, that may or may not have anything more than a command line interface. Sometimes a minimal, authenticated Web interface is imagined as a “nice to have” but nonessential feature, to display reporting information on the processing for example, and then it would be nice to have the option to quickly build something on top of the existing code base, that uses the same framework and therefore allows a consistent approach across all of the code in the project.

Although Rails is optimized for Web development, I suspect it could work well in both instances, at least for someone who knows what they’re doing. From there, it wouldn’t be difficult to think of things like creating other types of generators for other types of applications, using Rails in a wide variety of environments.

Now, I am not very good at coming up with original ideas, and sometimes it takes a while for important ideas to sink in (like adopting Rails for example). So, I assume that by the time I get around to recognizing something, its probably become obvious enough that a significant number of people have probably already explored it in some depth. Sure enough, I took a few shots in the dark and found some relevant sites when I Googled for “headless rails.” The links I followed seem to be more focused on convenient ways of testing and debugging standard Rails applications from the command line, but they offer some tantalizing clues for a newby like me about how one might use Rails without a Web interface. (I couldn’t immediately think of a better way to search for this idea.)

If any experienced Rails developers out there stumble upon this post, I would be extremely grateful if you could point me in the direction of any other work that may have been done along these lines, that might otherwise be difficult to find through Google. Or, let me know if this approach to using Rails sounds like a bad fit.

Otherwise, if I get a chance to explore this idea in my own in the near future, I will blog about it here.

In particular, I have an existing project that is evolving in an interesting way; it is a Java application for harvesting data from digital collections and ingesting it into a digital preservation system, aDORe. This was a relatively new area of development for my organization, and as you might expect, I got some parts of it right, others, well, not so right. If I am given the time, I would like to continue refactoring the code to better isolate all the major, reusable components that I got mostly right (which in turn rely on a number of mature, third-party open source libraries) and re-code what’s left over in Ruby. Essentially, Ruby would become the glue of the application, managing the Java components through JRuby. The Java code would handle the aspects of the application that are well understood (such as OAI-PMH harvesting) and the Ruby code would handle the more speculative, and potentially more innovative aspects of the application–the aspects that are more likely to change over time as I work on getting them right.

Also, the project has an iBatis layer that updates a separate MySQL database that is purely for recording various facts about the processing, which might in turn have a Web interface on top of it for reporting about the processing, as I described above. I could stop at the point that I have Ruby managing the Java components from a command line interface, or I could start to do things like replace the iBatis component with an ActiveRecord implementation either by using ActiveRecord outside of Rails somehow, or by coding the non-Java logic in Rails from the outset, possibly taking advantage of other pieces of Rails.

Feel free to tell me I’m crazy…I won’t be offended, or even terribly surprised.

Related Post