I'm writing my first Ruby command line application (beyond a simple
script) and I'm little unsure about how to structure the application and
the best use of require. I've come as far as to have the following file
structure:
myapp/
bin/
myapp
docs/ (RDOC files)
lib/
myapp.rb
myapp/
files and folders here
test/ (Test::Unit tests)
And the application is working, but there are a few things of which I am
unsure:
The bin/myapp file is a symlink to the lib/myapp.rb file which has a
shebang line. This doesn't really work, because inside lib/myapp.rb I
have:
require 'myapp/file'
require 'myapp/module/file'
which doesn't make sense when running the application from anywhere else
than myapp/lib
I also tried
$MYAPP_ROOT = File.expand_path(File.join(File.dirname(__FILE__),
'myapp'))
$LOAD_PATH << File.expand_path($MYAPP_ROOT)
Which still doesn't work because this also relies on cwd...
How do I work around this? What's the best practice way of making these
things make sense? Do you use the $RUBYLIB variable to set the full path
to the application? I was hoping to create the application as standalone
as possible, so installation will be easy.
···
--
Posted via http://www.ruby-forum.com/.