Class: Alki::Reload::Unloader
- Inherits:
-
Object
- Object
- Alki::Reload::Unloader
- Defined in:
- lib/alki/reload/unloader.rb
Instance Method Summary collapse
- #find_unloadable ⇒ Object
-
#initialize(handlers, whitelist = []) ⇒ Unloader
constructor
A new instance of Unloader.
- #unload(files:, consts:) ⇒ Object
Constructor Details
#initialize(handlers, whitelist = []) ⇒ Unloader
Returns a new instance of Unloader.
6 7 8 9 |
# File 'lib/alki/reload/unloader.rb', line 6 def initialize(handlers,whitelist=[]) @handlers = handlers @whitelist = whitelist end |
Instance Method Details
#find_unloadable ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# 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:) ⇒ Object
29 30 31 32 |
# 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 |