Module: Lich::Common::HMR
- Defined in:
- documented/common/hmr.rb
Overview
Hot Module Reloading functionality This module provides methods to clear cache, reload files, and send messages.
Class Method Summary collapse
-
.clear_cache ⇒ void
Clears the gem load paths cache.
-
.loaded ⇒ Array<String>
Returns a list of loaded Ruby files.
-
.msg(message) ⇒ void
Sends a message to the appropriate output.
-
.reload(pattern) ⇒ void
Reloads files matching the given pattern.
Class Method Details
.clear_cache ⇒ void
This method returns an undefined value.
Clears the gem load paths cache
17 18 19 |
# File 'documented/common/hmr.rb', line 17 def self.clear_cache Gem.clear_paths end |
.loaded ⇒ Array<String>
Returns a list of loaded Ruby files
37 38 39 |
# File 'documented/common/hmr.rb', line 37 def self.loaded $LOADED_FEATURES.select { |path| path.end_with?(".rb") } end |
.msg(message) ⇒ void
Note:
If the message contains HTML tags, it will be handled differently.
This method returns an undefined value.
Sends a message to the appropriate output
27 28 29 30 31 |
# File 'documented/common/hmr.rb', line 27 def self.msg() return _respond if defined?(:_respond) && .include?("<b>") return respond if defined?(:respond) puts end |
.reload(pattern) ⇒ void
Note:
This method clears the cache before reloading.
This method returns an undefined value.
Reloads files matching the given pattern
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'documented/common/hmr.rb', line 48 def self.reload(pattern) self.clear_cache loaded_paths = self.loaded.grep(pattern) unless loaded_paths.empty? loaded_paths.each { |file| begin load(file) self.msg "<b>[lich.hmr] reloaded %s</b>" % file rescue => exception self.msg exception self.msg exception.backtrace.join("\n") end } else self.msg "<b>[lich.hmr] nothing matching regex pattern: %s</b>" % pattern.source end end |