Where to install data files?

  • Thread starter Marek Janukowicz
  • Start date
M

Marek Janukowicz

Where should I install data files for the library I wrote? They are
connected with .rb files, so they should stay in the same directory, but
setup.rb does not install anything but .rb files from lib/ subdirectory.
The default data dir (/usr/share on my Gentoo Linux) does not seems
appropiate, too (I want my library to be installed in one place).

Maybe there should be something like java .jar files, which can contain
not only java class files, but also the resource files (corrent me if
I'm wrong)?
 
J

Jim Weirich

Marek Janukowicz said:
Where should I install data files for the library I wrote? They are
connected with .rb files, so they should stay in the same directory, but
setup.rb does not install anything but .rb files from lib/ subdirectory.
The default data dir (/usr/share on my Gentoo Linux) does not seems
appropiate, too (I want my library to be installed in one place).

Maybe there should be something like java .jar files, which can contain
not only java class files, but also the resource files (corrent me if
I'm wrong)?

You might consider creating a RubyGem. Each gems installs in its own
directory. See http://rubygems.rubyforge.org/wiki/wiki.pl
 
Z

Zachary P. Landau

--fwqqG+mf3f7vyBCB
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Where should I install data files for the library I wrote? They are
connected with .rb files, so they should stay in the same directory, but
setup.rb does not install anything but .rb files from lib/ subdirectory.
The default data dir (/usr/share on my Gentoo Linux) does not seems
appropiate, too (I want my library to be installed in one place).=20
=20
Maybe there should be something like java .jar files, which can contain
not only java class files, but also the resource files (corrent me if
I'm wrong)?

The nice thing about putting it in something like /usr/share is rbconfig
sets the location for you:

require 'rbconfig'
puts Config::CONFIG['datadir'] # =3D> /usr/share on my machine

That being said, I have one project that uses a .glade file. I decided
to put it next to the .rb files, as you said. I had to modify setup.rb
slightly to allow this though. I changed the following:

def ruby_scripts
collect_filenames_auto().select {|n| /\.rb\z/ =3D=3D=3D n }
end

to just

def ruby_scripts
collect_filenames_auto()
end

You could keep the select and just add your datafile extensions there
too, of course. Just as a bonus, this is the code I use to find the data
file in the ruby path:

def find_in_path(filename)
$LOAD_PATH.find do |dir|
try_file =3D File.join(dir, filename)
return try_file if File.readable?(try_file)
end
end

--
Zachary P. Landau <[email protected]>
GPG: gpg --recv-key 0x24E5AD99 | http://kapheine.hypa.net/kapheine.asc

--fwqqG+mf3f7vyBCB
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAIBa2CwWyMCTlrZkRAgu4AJ9TSAbds8/QYnMsKY9gd6SMmt88qgCeLmWD
ubemwhdEPPn3WwTvRvsL9CU=
=eiz7
-----END PGP SIGNATURE-----

--fwqqG+mf3f7vyBCB--
 

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

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top