rubyrubygemsruby-1.9.3

Ruby - Where to put resource files that a module in lib relies on?


I am trying to structure my ruby project following best practices. I currently have something like this:

test_project/
   bin/
       test_project # My Executable
   lib/
       test_project/
           my_module.rb
       test_project.rb # Loads my_module.rb

I setup it up this way based on recommendations I found on the web.

My problem is I have some resource files, "resouce1.txt" and "resouce2.txt". My executable needs to open the file "resource1.txt". my_module.rb needs to be able to open the file "resource2.txt". Where do I put these plan text resource files in this directory structure and how to I open them (File.open) from the corresponding ruby files.


Solution

  • Since /lib has to do with specifically the Ruby that powers your gems, I would put it in a top-level directory in your gem named after their subject matter. If they are files with lists of species I would call it /species.

    You could also go the Rails way and put it in an /assets folder if you have a lot of external assets like /assets/species. Either way, I would not be prone to put them in /lib.