-
Notifications
You must be signed in to change notification settings - Fork 0
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
Output when require happens, not after #4
Comments
After looking at the code, it seems this would require some changes: backload/lib/backload/require.rb Lines 20 to 29 in 44a1966
Before
... and add those "stubs" as well so they can easily be implemented. |
Well, here we go with a super crappy overload implementation of that: require 'backload'
require 'backload/require_relative'
module Kernel
def self.will_require(path)
end
private
#
# Alias backload's Kernel#require method.
#
alias_method :backload_require, :require
#
# Redefine Kernel#require with will_.
#
def require(feature, options=nil)
Kernel.will_require(feature)
backload_require(feature)
end
class << self
#
# Alias original Kernel.require method.
#
alias_method :backload_require, :require
#
# Redefine Kernel.require with callback.
#
def require(feature)
Kernel.will_require(feature)
backload_require(feature)
end
end
end
module Kernel
def self.will_require_relative(path)
end
private
#
# Alias backload's Kernel#require_relative method.
#
alias_method :backload_require_relative, :require_relative
#
# Redefine Kernel#require_relative with will_.
#
def require_relative(feature)
Kernel.will_require_relative(feature)
#backload_require_relative feature
## We have to reimplement #require_relative instead of calling
## the alias to ensure the proper path is used. (*sad*)
result = (
c = caller.first
fail "Can't parse #{c}" unless c.rindex(/:\d+(:in `.*')?$/)
file = $` # File.dirname(c)
if /\A\((.*)\)/ =~ file # eval, etc.
raise LoadError, "require_relative is called in #{$1}"
end
#options[:relative] = File.dirname(file)
absolute = File.expand_path(feature, File.dirname(file))
backload_require_relative(absolute)
)
end
class << self
#
# Alias original Kernel.require_relative method.
#
alias_method :backload_require_relative, :require_relative
#
# Redefine Kernel.require_relative with will_.
#
def require_relative(feature)
Kernel.will_require_relative(feature)
#backload_require_relative feature
## We have to reimplement #require_relative instead of calling
## the alias to ensure the proper path is used. (*sad*)
result = (
c = caller.first
fail "Can't parse #{c}" unless c.rindex(/:\d+(:in `.*')?$/)
file = $` # File.dirname(c)
if /\A\((.*)\)/ =~ file # eval, etc.
raise LoadError, "require_relative is called in #{$1}"
end
#options[:relative] = File.dirname(file)
absolute = File.expand_path(feature, File.dirname(file))
backload_require_relative(absolute)
)
end
end
end
def Kernel.will_require(feature)
puts "will require '#{feature}'"
end
def Kernel.will_require_relative(feature)
puts "will require_relative '#{feature}'"
end Could really easily be turned into a feature of this, but we should probably talk about the naming then. |
While looking into #2 I noticed that (of course) the callback for a
require
is only fired after all therequire
s inside are taken care of.Is there a way to execute something when the
require
starts, so it is easier to understand in what order things are required?The text was updated successfully, but these errors were encountered: