Class Atchoum::Reloader
In: lib/atchoum/reloader.rb
Parent: Object

Reloads the application whenever the script is changed. Inspired by _why’s Camping Reloader code.whytheluckystiff.net/svn/camping/trunk/lib/camping/reloader.rb

Methods

find_class   new   reload   unload_class  

Attributes

class_name  [R] 
instance  [R] 

Public Class methods

[Source]

    # File lib/atchoum/reloader.rb, line 8
 8:     def initialize(script)
 9:       @script = File.expand_path(script)
10:       @class_name = script.scan(/(\w+).rb$/)[0].first.capitalize.gsub(/_(\w)/) { $1.to_s.upcase }
11:     end

Public Instance methods

[Source]

    # File lib/atchoum/reloader.rb, line 13
13:     def find_class
14:       @klass = Object.const_get(Object.constants.grep(/^#{@class_name}$/i)[0]) rescue nil
15:       @instance = @klass.new
16:     end

Reload the script

[Source]

    # File lib/atchoum/reloader.rb, line 25
25:     def reload
26:       # TODO maybe check for timestamp ?
27:       unload_class
28:       load @script
29:       find_class
30:     end

[Source]

    # File lib/atchoum/reloader.rb, line 18
18:     def unload_class
19:       Object.send :remove_const, @klass.name if @klass
20:       @klass = nil
21:       @instance = nil
22:     end

[Validate]