Managing Environments for ruby apps

R

Robert Evans

Hi all,

Over the last couple of years I have accumulated a fair amount of
Ruby code across a couple of projects at work, and I have factored
out several components into reusable libraries, although I haven't
needed to turn them into gems yet. Each component looks like a
standard library with subdirectories for lib and test. Lib has the
code and test has the tests. I have rake files for running tests and
various other subdirectories for support resources in the root of
each component.

To manage the project dependencies, I setup a common config.rb then I
call that from my application to fill the loadpath with the required
libraries. This allows me to keep my various libraries and rb files
portable by just adding in a require "config" and then simple
"require"'s for any given dependencies in the class, without
specifying path info in the require arg. It grew out of a desire for
modularity as my scripts became applications and spanned multiple
projects.

This simple step has made it easy to manage my various applications
and my libraries on which they depend. I have also paid particular
interest to how Rails manages its load path and environment. I am
curious how others approach the issue of managing ruby projects that
have dependencies on each other. I am sure there might be other
clever ways to manage it without going all the way to using gems as
that seems kind of heavy for internal projects that all share the
same version control tree.

Thanks,
Bob Evans
http://www.junitfactory.com/
Send Java Get Junit
 
J

Joel VanderWerf

Robert said:
Hi all,

Over the last couple of years I have accumulated a fair amount of Ruby
code across a couple of projects at work, and I have factored out
several components into reusable libraries, although I haven't needed to
turn them into gems yet. Each component looks like a standard library
with subdirectories for lib and test. Lib has the code and test has the
tests. I have rake files for running tests and various other
subdirectories for support resources in the root of each component.

To manage the project dependencies, I setup a common config.rb then I
call that from my application to fill the loadpath with the required
libraries. This allows me to keep my various libraries and rb files
portable by just adding in a require "config" and then simple
"require"'s for any given dependencies in the class, without specifying
path info in the require arg. It grew out of a desire for modularity as
my scripts became applications and spanned multiple projects.

This simple step has made it easy to manage my various applications and
my libraries on which they depend. I have also paid particular interest
to how Rails manages its load path and environment. I am curious how
others approach the issue of managing ruby projects that have
dependencies on each other. I am sure there might be other clever ways
to manage it without going all the way to using gems as that seems kind
of heavy for internal projects that all share the same version control
tree.

Thanks,
Bob Evans
http://www.junitfactory.com/
Send Java Get Junit

If your file system supports symlinks, you can have something like this

$ export RUBYLIB=$HOME/ruby/lib:$RUBYLIB

and ruby/lib has links like this:

somelib -> ../somelib/lib/somelib
somelib-main-file.rb -> ../somelib/lib/somelib-main-file.rb

(Typically, I have two links for each project.)

This is assuming you keep your library project dirs in $HOME/ruby/ --
adjust as desired. (These are your checked-out working directories for
the library prpjects.)

You can then require libraries in the usual way:

require 'somelib-main-file'
require 'somelib/extras'

Installed programs use exactly the same require calls to reference this
library, assuming you either use the standard install.rb or follow the
same convention.

The advantage is that you don't have to install locally when you are
working on a particular project in order for other projects to use the
latest version.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top