Class: CodeReloader

Inherits:
Object
  • Object
show all
Defined in:
lib/liquid/code_reloader.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ CodeReloader

Returns a new instance of CodeReloader.



5
6
7
8
9
10
11
12
13
# File 'lib/liquid/code_reloader.rb', line 5

def initialize(path)
  $log.warn("code.reloader", active: true, path: path)
  Listen.to(path) do |m, a, r|
    Thread.name = "Code Reloader (#{path})"
    (m + a).uniq.each do |file|
      reload(file)
    end
  end.start
end

Instance Method Details

#reload(file) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/liquid/code_reloader.rb', line 15

def reload(file)
  if file =~ /\.rb$/
    $log.info("code.reloader", reload: file)
    begin
      load(file)
    rescue SyntaxError => e
      $log.exception(e)
    rescue => e
      $log.exception(e)
    end
  end
end