Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Ruby gem newbie question

Reply
Thread Tools

Ruby gem newbie question

 
 
David Madden
Guest
Posts: n/a
 
      05-16-2008
Hi,

I am trying to create a ruby gem and I have a slight problem finding a
file within it.

The structure of the code in my gem is as follows:

/
bin/
ai
lib/
app.rb
app/
# src files
templates/
default.txt
etc.

The gem loads fine, my problem is that I cannot find the default.txt
file in the templates dir from within the code in the app dir when it is
used from the command line.

I think it is trying to find the file in the working directory, but it
is inside the gem. I have a line in my src file:

DEFAULT = "../templates/default.txt"

What should I put in order to point to the file within the gem?

Thanks.

David.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
David Madden
Guest
Posts: n/a
 
      05-16-2008
Ok, I found a fix. I am not sure if this is the correct way but it seems
to work.

TEMPLATE_DIR = "/../templates/"
DEFAULT = "default.txt"

template = File.dirname(__FILE__) + TEMPLATE_DIR + DEFAULT

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
gemspec: How to install a Ruby extension into GEM/lib/SOME_DIR/rather than GEM/lib/ IƱaki Baz Castillo Ruby 1 02-28-2011 03:26 PM
RubyGems 0.9.1 calling a gem with gem '<gem>' Austin 7873 Ruby 5 01-27-2007 10:05 PM
[GEM PATCH] allow gem to install bin file to different location Ara.T.Howard Ruby 0 10-26-2005 11:52 PM
ERROR: While executing gem ... (Gem::GemNotFoundException) Could not find rubygems-upodate (> 0) in the repository han Ruby 1 10-24-2005 10:28 PM
[ANN] Getopt-Declare 1.12 (gem/zip) and GGEnv (gem/zip) gga Ruby 0 07-18-2005 03:21 PM



Advertisments