Module: Lich::Common::HMR
- Defined in:
- lib/common/hmr.rb
Class Method Summary collapse
-
.clear_cache ⇒ void
Clears the gem cache by calling ‘Gem.clear_paths`.
-
.loaded ⇒ Array<String>
Retrieves a list of loaded Ruby files.
-
.msg(message) ⇒ void
Sends a message to the appropriate output method.
-
.reload(pattern) ⇒ void
Reloads files that match the given pattern.
Class Method Details
.clear_cache ⇒ void
This method returns an undefined value.
Clears the gem cache by calling ‘Gem.clear_paths`.
11 12 13 |
# File 'lib/common/hmr.rb', line 11 def self.clear_cache Gem.clear_paths end |
.loaded ⇒ Array<String>
Retrieves a list of loaded Ruby files.
37 38 39 |
# File 'lib/common/hmr.rb', line 37 def self.loaded $LOADED_FEATURES.select { |path| path.end_with?(".rb") } end |
.msg(message) ⇒ void
This method returns an undefined value.
Sends a message to the appropriate output method.
If ‘_respond` is defined and the message contains “<b>”, it will call `_respond`. If `respond` is defined, it will call `respond`. Otherwise, it will print the message.
25 26 27 28 29 |
# File 'lib/common/hmr.rb', line 25 def self.msg() return _respond if defined?(:_respond) && .include?("<b>") return respond if defined?(:respond) puts end |
.reload(pattern) ⇒ void
This method returns an undefined value.
Reloads files that match the given pattern.
This method clears the cache, finds files matching the pattern, and attempts to load them. If loading fails, it captures and reports the exception.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/common/hmr.rb', line 53 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 |