Module: Lich::Common::HMR

Defined in:
documented/common/hmr.rb

Class Method Summary collapse

Class Method Details

.clear_cachevoid

This method returns an undefined value.

Clears the gem load paths cache.



10
11
12
# File 'documented/common/hmr.rb', line 10

def self.clear_cache
  Gem.clear_paths
end

.loadedArray<String>

Returns an array of loaded Ruby files.

Returns:

  • (Array<String>)

    list of loaded Ruby file paths



27
28
29
# File 'documented/common/hmr.rb', line 27

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.

If the message contains HTML, it will be handled by the _respond method if defined.

Parameters:

  • message (String)

    the message to be sent



19
20
21
22
23
# File 'documented/common/hmr.rb', line 19

def self.msg(message)
  return _respond message if defined?(:_respond) && message.include?("<b>")
  return respond message if defined?(:respond)
  puts message
end

.reload(pattern) ⇒ void

This method returns an undefined value.

Reloads files matching the given pattern.

This method clears the cache and reloads all files that match the provided regex pattern.

Parameters:

  • pattern (Regexp)

    the pattern to match file paths

Raises:

  • (LoadError)

    if a file cannot be loaded



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'documented/common/hmr.rb', line 37

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.message
        self.msg exception.backtrace.join("\n")
      end
    }
  else
    self.msg "<b>[lich.hmr] nothing matching regex pattern: %s</b>" % pattern.source
  end
end