Re: How to reliably setup require path





On Apr 14, 8:15 am, Christian Johansen <chrisj...@xxxxxxxxx> wrote:
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)

I would suggest:

myapp/
bin/
myapp
doc/
rdoc/ (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:

Don't use a symlink. Make something like lib/myapp/command.rb, then in
the bin:

require 'myapp/command'

MyApp::Command.start # or what have you

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.

To run your app you will need to first go through an install phase.
There a few ways to do this. The oldest is to add setup.rb to you
project and run that between trying your app out. Another is to
generate a .gem and install that between trial runs (you can automate
this process for convenience). In my case, I use Rolls, but it's still
a little rough around the edges so I'm not actively recommending it to
anyone yet. But you can contact me off list if you'd like to do so.

On the other hand, if you do TDD you don't really need go through an
install phase often. Your test runner should add lib/ to the
$LOAD_PATH. So you can run your tests without ever installing your
app.

HTH,
T.

.



Relevant Pages

  • Re: IP Retrieval
    ... I thought of ipconfig and netsh as ways to retrieve the ip but I am unsure ... > you to install php or something to all machines.. ... > This will show the LAN IP because you access ... > something to the host end.. ...
    (alt.php)
  • Re: Reformating XP queries
    ... Unsure of the procedure i have been browsing ... I am struck by the terms FAT32 and ... and after the license agreement take New Install. ...
    (microsoft.public.windowsxp.general)
  • Re: Lost Windows XP OEM
    ... I am unsure if it'd work, but you could maybe try downloading the Magical Jellybean keyfinder and see if it displays the XP key as well as the Vista key? ... I purchased a Vista upgrade and installed that on ... install but I can't find my Windows XP OEM anywhere. ... Do I need to purchase a ...
    (microsoft.public.windowsxp.general)
  • Re: explorer.exe error
    ... I had to install the update sp2 or there i think is a single download for ... this i'm unsure it was all automatic for me ...
    (microsoft.public.windowsxp.general)
  • Re: ClickOnce Nightmares
    ... your app need to install the settings. ... LAN) you could create a logon script that will automatically install the ... DownloadOptions options, ServerInformation& serverInformation) ... FileAccess access, Boolean asyncHint) ...
    (microsoft.public.dotnet.framework)