Noobie question - how do I run this command-line program?

Hi. I downloaded a tiny ruby app called EarGTD and I am trying to get
it to run at the command line. It is a simple program consisting of
about four files. You can read about it here:

When I download and unzip the file, I get the following directory
structure:

EarGTD/
.DS_Store
Rakefile
data/
test_ear_gtd.db
earGTD*
lib/
ear_gtd.rb
test/
test_ear_gtd.rb

The entire contents of the earGTD file, which is the file which
launches the app, are as follows:

#!/usr/bin/env ruby
require “lib/ear_gtd”
EarGTD.connect
EarGTD.process_command(ARGV)

The problem I am having is that when I launch the app, I get the
following error:

internal:lib/rubygems/custom_require:29:in require': no such file to load -- lib/ear_gtd (LoadError) from <internal:lib/rubygems/custom_require>:29:inrequire’
from ./earGTD:2:in `’

I understand that the earGTD is trying to load lib/ear_gtd.rb - which
is in the lib file in the same directory. But for some reason the
ruby path loading system doesn’t know how to find it. I have modified
/etc/bashrc to put my current directory in the $PATH, but that didn’t
make a difference.

If you can tell me what is going on, I would much appreciate it.

Thanks,

Jon

On 18/10/11 08:19, Jon Crowell wrote:

 data/

to load – lib/ear_gtd (LoadError)

Thanks,

Jon
Could you try;

ruby -I/path/to/EarGTD /path/to/EarGTD/earGTD

This will tell ruby to add that path to the LOAD_PATH before running the
script. I don’t think Ruby searches your path - which is no doubt for
security reasons.

Sam

On Mon, Oct 17, 2011 at 2:19 PM, Jon Crowell
[email protected]wrote:

.DS_Store
The entire contents of the earGTD file, which is the file which

If you can tell me what is going on, I would much appreciate it.

Thanks,

Jon

Ruby programs look for files that are required in a global variable
called
$LOAD_PATH. In old Ruby, the directory you are in when you invoke the
app is
added to the $LOAD_PATH. If you were sitting in the directory as earGTD
in
old Ruby, it would then be able to find 'lib/ear_gtd" when it requires
it,
because that is where the file is, relative to where you are in your
directory.

This was deemed a security risk, because it meant you could accidentally
run
code without intending to. So now you must either pass the full path to
the
file you are requiring, or you must alter the load path to include a dir
that you can require files relatively to.

The easiest solution for this particular use case is to just require the
full path. Change require "lib/ear_gtd" to require File.expand_path('../lib/ear_gtd', __FILE__)

Wow, thanks. That was a perfect explanation for the behavior I
witnessed. The solution that you proposed works.

Now my problem is that the second line of lib/ear_gtd.rb, which ruby
can now find, which reads:

require “active_record”

is causing ruby to throw up its hands. I guess this is where I need
to use and understand Bundler for dependency management, is that
right?

Thanks,

Jon

On Mon, Oct 17, 2011 at 2:54 PM, Jon Crowell
[email protected]wrote:

right?

Not for this application, it is not using Bundler (you can tell a Ruby
program is using Bundler because it will have a file at the root of the
app
named Gemfile). The easiest thing to do is probably to guess at what
version
of ActiveRecord it needs and install that. If you find yourself doing
this a
lot, then it is probably worth it to add Bundler to the project. I’d try
matching the date of the article up against versions at
https://rubygems.org/gems/activerecord/versions then install that
particular
version of ActiveRecord with $ gem install activerecord -v x.x.x If
you
have newer versions of ActiveRecord installed, then you may need to add
gem 'activerecord', '=x.x.x' to the code to force it to load the version
you
want (if this process is as eyebrow raising to you as it is to me, then
you
see why Bundler was created).

Thanks so much. This has been a real help to me.

Jon

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs