Class: FileReload::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/lre/file_reload.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#on_every_fileObject

Returns the value of attribute on_every_file.



9
10
11
# File 'lib/lre/file_reload.rb', line 9

def on_every_file
  @on_every_file
end

#scriptObject

Returns the value of attribute script.



9
10
11
# File 'lib/lre/file_reload.rb', line 9

def script
  @script
end

Instance Method Details

#process_file(f, &b) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lre/file_reload.rb', line 11

def process_file(f,&b)
  if !FileTest.exists?(f)
    puts "file doesn't exist #{f}"
    return
  end
  on_every_file[File.expand_path(f)] if on_every_file
  puts "loading #{f}"
  b[f]
  print ">"
rescue => exp
  puts "error loading #{f}"
  puts exp.message + "\n" + exp.backtrace.join("\n")
rescue SyntaxError => exp
  puts "syntax error loading #{f}"
  puts exp.message + "\n" + exp.backtrace.join("\n")
rescue RuntimeError => exp
  puts "runtime error"
  puts exp.message
end

#run!Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/lre/file_reload.rb', line 41

def run!
  require 'watchr'
  require 'pathname'
  self.script = Watchr::Script.new
  watches.each do |file_match,proc|
    script.watch(file_match) do |md|
      f = md[0]
      process_file(f,&proc)
    end
  end
  
  self.threads.each { |x| x.kill }
  self.threads = []
  
  LRE.watch_dirs.uniq.each do |d|
    c = Watchr::Controller.new(script, Watchr.handler.new)
    c.base_path = d
    puts "adding thread #{d}"
    self.threads << Thread.new { c.run }
  end
end

#stop!Object



30
31
32
33
# File 'lib/lre/file_reload.rb', line 30

def stop!
  self.threads.each { |x| x.kill }
  self.threads = []
end