class Alki::Reload::Unloader
Public Class Methods
new(handlers,whitelist=[])
click to toggle source
# File lib/alki/reload/unloader.rb, line 6 def initialize(handlers,whitelist=[]) @handlers = handlers @whitelist = whitelist end
Public Instance Methods
find_unloadable()
click to toggle source
# File lib/alki/reload/unloader.rb, line 11 def find_unloadable files = [] consts = [] $LOADED_FEATURES.each do |path| if path.end_with?('.rb') result = @handlers.lazy.map{|h| h.handle_path path }.find{|r| r != nil} if result if add_const consts, result files << path end end end end unless files.empty? {files: files, consts: consts} end end
unload(files:, consts:)
click to toggle source
# File lib/alki/reload/unloader.rb, line 29 def unload(files:, consts:) $LOADED_FEATURES.delete_if {|f| files.include? f} consts.each {|(parent,const)| parent.send :remove_const, const} end
Private Instance Methods
add_const(consts,name)
click to toggle source
# File lib/alki/reload/unloader.rb, line 36 def add_const(consts,name) unless @whitelist.include? name md = name.match(%r{(.*)/(.*)}) if md parent = Alki::Support.constantize Alki::Support.classify md[1] name = md[2] else parent = Object end name = Alki::Support.classify(name).to_sym if parent && parent.is_a?(Module) && parent.const_defined?(name,false) consts << [parent,name] true end end end