lib/polyglot.rb in polyglot-0.1.0 vs lib/polyglot.rb in polyglot-0.2.0

- old
+ new

@@ -1,9 +1,10 @@ $:.unshift File.dirname(__FILE__) module Polyglot @registrations ||= {} # Guard against reloading + @loaded ||= {} def self.register(extension, klass) extension = [extension] unless Enumerable === extension extension.each{|e| @registrations[e] = klass @@ -20,23 +21,29 @@ return [ path, @registrations[path.gsub(/.*\./,'')]] end } return nil end -end -module Kernel - alias polyglot_original_require require - - def require(*a, &b) - polyglot_original_require(*a, &b) - rescue LoadError => load_error + def self.load(*a, &b) + return if @loaded[a[0]] # Check for $: changes or file time changes and reload? begin source_file, loader = Polyglot.find(*a, &b) if (loader) loader.load(source_file) + @loaded[a[0]] = true else raise load_error end end + end +end + +module Kernel + alias polyglot_original_require require + + def require(*a, &b) + polyglot_original_require(*a, &b) + rescue LoadError => load_error + Polyglot.load(*a, &b) end end