Module: Rucola::Reloader
- Defined in:
- lib/rucola/reloader.rb
Overview
The Reloader
watches the app/controllers path and reloads a class if it notices that a file has been changed.
Class Method Summary collapse
-
.reload(file) ⇒ Object
Reload a file (class).
-
.start! ⇒ Object
Start watching app/controllers for a file modification and reload that class.
Class Method Details
.reload(file) ⇒ Object
Reload a file (class).
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rucola/reloader.rb', line 17 def reload(file) klass = File.to_const(file) begin File.read(file).parse_to_nodes log.debug "Reloading class #{klass.name}:" i_methods = klass.instance_methods(false) log.debug "- Undefining instance methods: #{i_methods.inspect}" i_methods.each { |mname| klass.send(:undef_method, mname) } c_methods = klass.original_class_methods log.debug "- Undefining class methods: #{c_methods.inspect}" c_methods.each { |mname| klass..send(:undef_method, mname) } Kernel.load(file) rescue SyntaxError => e log.error "WARNING: Reloading the class #{klass.name} would have caused a parse error:\n#{e.}" end end |
.start! ⇒ Object
Start watching app/controllers for a file modification and reload that class.
10 11 12 13 14 |
# File 'lib/rucola/reloader.rb', line 10 def start! Rucola::FSEvents.start_watching(Rucola::RCApp.controllers_path, Rucola::RCApp.models_path) do |events| events.each { |event| reload(event.last_modified_file) } end end |