Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading parts of a Rails 3 application

I am developing a gem for Rails 3 that consists of two main components. The first is a rails generator that adds some new files/folders to a rails project. The second is a runtime environment that loads all the aforementioned files (some ruby classes that use my DSL) as well as a portion of the default Rails stack. Essentially it's everything you'd expect to be able to access in rails c, sans routing, controllers, helpers and views. What is the proper way to load a Rails environment, except for specific portions?

Sidenote: I'd love to see any good articles regarding requiring Rails applications.

like image 401
bloudermilk Avatar asked Nov 04 '22 22:11

bloudermilk


1 Answers

I am not entirely clear what you mean, or if this will help, but it sounds similar to something I do in a utility I wrote.

My utility loads the environment like so:

#!/usr/bin/env ruby
require File.expand_path('../../config/environment',  __FILE__)

The require of the ../../config/boot will cause the gems defined in your Gemfile to load. So if you needed only part of the Rails stack then you would only require that part of the stack in your Gemfile.

This gives me my rails context, access to models and other resources.

(UPDATE) To skip parts of the rails stack - take a look at how its been done to swap out ActiveRecord: http://www.mongodb.org/display/DOCS/Rails+3+-+Getting+Started

Hope that helps.

like image 180
johnmartirano Avatar answered Nov 09 '22 14:11

johnmartirano