-
Notifications
You must be signed in to change notification settings - Fork 745
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
Fix multiple load when running rougify -r ...
#1566
base: master
Are you sure you want to change the base?
Conversation
except through `reload!` which properly removes the previous version first
b6390b9
to
05840b6
Compare
This is failing because ruby 2.3 and earlier do not support top-level However, we can solve the same problem by using a |
Er.... hang on no we can't. That would still allow multiple versions of Rouge to be loaded in the same runtime. |
# Avoid multiple loads (top-level return will be possible when 2.4+ is the | ||
# minimum supported version) | ||
unless Object::const_defined?(:Rouge) && Rouge.const_defined?(:LIB_DIR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jneen According to these notes, this was the alternative approach before top-level return. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jneen How does this look to you?
If the required file contains
require 'rouge'
(which should be unnecessary when usingrougify
but might be there for other purposes), we currently catastrophically load another copy of Rouge, which may be from a different version. This prevents that with a simple definition guard.I know it looks hacky, but it's the only way to have proper reload semantics.
Rouge.reload!
continues to work with this, because theRouge
constant will be removed from the toplevel first.(edit: accidentally pushed the wrong branch, this is 1 commit)