Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recursively including all model subdirectories

Tags:

How do you load all directories recursively in the models and lib directories? In application.rb, I have the lines:

config.autoload_paths += Dir[Rails.root.join('app', 'models', '{**}')] config.autoload_paths += Dir[Rails.root.join('lib', '{**}')] 

but they only seem to add one level of model and lib subdirectories.

Thanks

like image 736
GTDev Avatar asked Oct 13 '11 07:10

GTDev


People also ask

How do you recursively list subdirectories?

Linux recursive directory listing using ls -R command. The -R option passed to the ls command to list subdirectories recursively.

How do I list files in all subdirectories?

By default, ls lists just one directory. If you name one or more directories on the command line, ls will list each one. The -R (uppercase R) option lists all subdirectories, recursively.

How can I recursively grep through subdirectories?

Grep command is used to search text from files. It is a versatile pattern that invokes grep with –r. –R option search files recursively from subdirectories, starting from the current directory. The command is run from the top-level directory.

What does recursively mean in Linux?

Alternatively referred to as recursive, recurse is a term used to describe the procedure capable of being repeated. For example, when listing files in a Windows command prompt, you can use the dir /s command to recursively list all files in the current directory and any subdirectories.


1 Answers

this should be helpful

 Dir["#{config.root}/app/models/**/","#{config.root}/lib/**/"] 

enjoy! (:

Update:

Excellent question, posting example above i have simply referred to my recent project.

After making some tests, better understanding comes to me and it is great.

The main difference is of course neither in join method of File not config.root / Rails.root

Trailing '/' after '**' makes sense.

First one talks to match only directories when globbing. Second one talks do it recursively.

In your case this one could be also appropriate

Dir[ Rails.root.join('app', 'models', '**/') ] 
like image 148
sarvavijJana Avatar answered Oct 26 '22 06:10

sarvavijJana