sam / harbor

Harbor is a Ruby Web Framework.
https://github.com/sam/harbor
MIT License
3 stars 6 forks source link

Avoid requiring controllers one by one and require all files on /controllers #60

Closed fgrehm closed 12 years ago

fgrehm commented 12 years ago

This will make the generated app require all controllers from controllers folder so we don't need to remember to add a require_relative "../controllers/<new_controller>" to lib/<app_name>.rb

fgrehm commented 12 years ago

BTW, this made me think of what would be the use of the generated lib/boot.rb as we now have a place to initialize the application and to configure things. Is it really necessary? If it is, we should probably add some comments there to explain what should go there :-)

fgrehm commented 12 years ago

Also, if you guys like this idea of requiring everything, we should probably have the same support for helpers, forms and models

sam commented 12 years ago

Definitely. I'm probably out of the loop for a few days yet after moving this past weekend but I'll try to get your PRs merged tonight.

sam commented 12 years ago

The generated boot.rb is just a file we can require that knows the app_name.rb. harbor console makes use of this for example (and harbor server eventually).

sam commented 12 years ago

I'm going to go ahead and merge this for now, but I'd like to see a more sophisticated auto-loader, as you suggested previously since globbing the files can introduce require-order issues forcing you to add the occasional manual require.

fgrehm commented 12 years ago

@sam the problem with autoloading controllers is that we will never have routes available unless we explicitly require them, its not like rails that you have the routes defined in a separate file which will trigger controllers auto load when a request comes in... the same applies to #62, we need to actually require the helpers to be able to include them on ViewContext... IMO we might have autoloading in place but for other stuff rather than controllers and helpers. we could maybe have it handling controller inheritance / module inclusion

sam commented 12 years ago

So after talking about this, the goal is to not have to manually require stuff, and to have it reload nicely once modified.

It's not a requirement that the code load lazily. That might help out startup time, but until it actually becomes an issue it isn't a concern.

Adding the appropriate hooks so the code auto-loads/reloads, then performing a glob-require on the appropriate folder should do what we want then (by adding the hooks first, if controllers/foo.rb refers to a Controller::Bar constant, we won't have issues with the glob-require since the autoload hook will catch the const_missing).