-
Notifications
You must be signed in to change notification settings - Fork 18
autoloading multiple files
The rails autoload algorithm will only load the first file it finds.
a couple of solutions:
- for classes like ServerOp and ActiveRecord::Base we could during the class definition look for a second file in an alternative directory. for example
# app/operations/foo.rb
class Foo < ServerOp
...
end
when Foo is defined it automatically looks for a file named app/hyperloop/operations/foo.rb
probably using the directory path of the original foo and inserting 'hyperloop' (which could be defined in a config file)
- variant on the first where we have some directive like
load_inteface 'hyperloop'
class Foo < ServerOp
interface :hyperloop
end
- does the simple way work?
require 'hyperloop/operation/foo_public.rb`
class Foo < ServerOp
end
its just a little extra typing...
- modify rails autoload:
https://github.com/rails/rails/blob/f243e7f0d0b2cef350127fd518532fedb65f0bd0/activesupport/lib/active_support/dependencies.rb#423 (add search_for_file that is like search_for_files)
update https://github.com/rails/rails/blob/f243e7f0d0b2cef350127fd518532fedb65f0bd0/activesupport/lib/active_support/dependencies.rb#493 (load_missing_constant) so that it loads all the files returned by search_for_files.
Only trouble with this is perhaps sometimes libs and gems using shadowing on the autoload path?