-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Defining a module that fails to load, makes other modules that include it not have methods #8
Comments
Can you change your example to have some method(s) defined as well so it's possible to reproduce that problem fully? |
In an empty directory create three files # a.rb
module A
puts "A about to include B"
include ::B
puts "A finished including B"
end # b.rb
module B
puts "B about to include C"
include ::C
puts "B finished including C"
end module C
def c_method
puts "I am C"
end
end And then a fourth file called # run.rb
require 'require_all'
puts "Calling require_all on PWD"
$: << '.'
require 'c'
require 'b'
require 'a'
#require_all '.'
puts "Done with require_all"
puts "A has instance methods which are #{A.instance_methods}" Initially we'll just do it with require in reverse order from C->A and the output of this will be
Here we see that A when all is said and done has a method on it called However if we change
Not totally sure why it runs it twice but I think that it's require_all retrying after a LoadError or something. But at the end A does not have the method defined on C. |
I purposely named the files a, b, and c to show that require_all does this when the files are sorted because it sorts the file list before requiring. This isn't bad but there is a chance this will all work if the file names are sorted the other way. For example if A was named C and visa versa this all works because A has the method and is loaded first. |
If we had a handy way of knowing what constants were defined before we attempted to load a file and what constants are defined after the attempted file load, we could remove from memory any new constants if a file fails to load cleanly, yes? |
Probably. I guess we should start by creating failing test and then trying Anyway, it's worth to try. On Tue, Oct 27, 2015 at 1:00 AM, Eric Kessler notifications@github.com
|
There's a decent chance of a performance hit, yes, but I would think that the most common use case of this gem are one time calls at startup. I mean, this gem is kind of a 'here's a pile of stuff, please figure it out for me' sort of thing. So we are theoretically dealing with users who aren't super reliant on performance or else they would already be taking the extra care of managing their file requiring on their own. |
Waiting for a possible fix/pull request. I do not probably have time to do that so if there's someone willing, I'd happily accept a pull request. Thanks! |
I just ran into this myself. Luckily I recall this issue existing, so I didn't waste too much time determining what was wrong and adding at least a little order to how I pull in files. Still, it would be nice if we could get this solved. |
Still waiting for a PR. Closing this due to inactivity until then. |
This is exactly the sort of issue that is difficult/impossible to fix given the way Regarding the earlier suggestion in this issue by @enkessler, ie of tracking which constants are defined before each file is required and unloading newly-added ones in the case of errors, I can see at least three very-hard-to-solve/unsolvable issues with that approach:
|
Module A includes module B which includes module C
When start none are defined. Files are required in sorted order A,B then C
A now does not have the methods you would expect and everything loaded cleanly.
I now understand the problem but I'm having a hard time coming up with a not awful solution to it.
Any thoughts?
The text was updated successfully, but these errors were encountered: