presidentbeef/brakeman — pull request #197 by brynary (2012-12-03 04:09:55+00:00)
Title: Refactor: Introduce AppTree as facade for filesystem

The idea of this refactoring is to have a single object responsible for access to the app files on disk. This is useful for my purposes, but also cleans up the code a bit. In particular, the logic to skip files was repeated in Scanner. Also the AppTree serves as a convenient place to memoize the results of the expensive disk calls.

I believe this is comprehensive, but my main tool was grepping for File.exist[s]?, Dir.glob, and File.read calls. I may have missed one somewhere.

Rather stuffing the AppTree object somewhere like options hash (which is available pretty much everywhere), I elected to keep it separate, as it seems important enough to be passed into the initializers. This did make it more evident that there are a number of classes that might reachout to the filesystem directly, as low level as ControllerAliasProcessor, which is something that might be worth improving.

Finally, this exposed a potential bug: The allowable extensions for determining if a layout exists are not quite identical to those that are searched for templates normally. Specifically, it ignore *.rhtml templates. In order to remain behavior neutral, I did not fix this, but it's quite evident in AppTree#layout_exists? not using VIEW_EXTENSIONS.

Note: This is not being used for the install_rake_task behavior. I could go either way on this, but left it for now as it feels more like a utility function that doesn't play by the same rules as the scanning process.

What do you think?