views:

132

answers:

1

In environment.rb I can add the line

config.load_paths += %W( #{RAILS_ROOT}/app/models/foos )

where 'foos' is a folder. This loads all files inside the foos folder. However it doesn't load any of its subdirectories.

If I knew the names of all the subdirectories in the 'foos' folder, this problem would have an easy solution:

%W[folder1 folder2 folder2].each { |f| f.config.load_paths += %W( #{RAILS_ROOT}/app/models/foos/#{f} ) }

However, I won't always know the names of all folders inside of 'foos'. Is there someway to do this:

config.load_paths += %W( #{RAILS_ROOT}/app/models/foos/#{**WILDCARD**} )

Thanks

+2  A: 

It looks like this other question has the type of solution you are looking for to get all the sub directories:

http://stackoverflow.com/questions/800189/get-all-of-the-immediate-subdirectories-in-ruby

You can use something like the following to point at a particular directory and get a list of all the sub directories of it:

Dir['/home/username/Music/*/']

This will return an array of all the paths to the sub directories of the Music folder.

Pete
Looks good. Could you help me adapt that method to work with in environment.rb.For example, Dir.glob("**/") finds all the subdirectories of the *current* directory. I want to point to a different directory whose subdirectories I want to load.
updated the answer to hopefully help you target a particular directory.
Pete