Class: Dasht::Reloader
- Inherits:
-
Object
- Object
- Dasht::Reloader
- Defined in:
- lib/dasht/reloader.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #changed? ⇒ Boolean
-
#initialize(parent) ⇒ Reloader
constructor
A new instance of Reloader.
- #run ⇒ Object
Constructor Details
#initialize(parent) ⇒ Reloader
Returns a new instance of Reloader.
5 6 7 8 |
# File 'lib/dasht/reloader.rb', line 5 def initialize(parent) @parent = parent @last_modified = File.mtime($PROGRAM_NAME) end |
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
3 4 5 |
# File 'lib/dasht/reloader.rb', line 3 def parent @parent end |
Instance Method Details
#changed? ⇒ Boolean
10 11 12 |
# File 'lib/dasht/reloader.rb', line 10 def changed? @last_modified != File.mtime($PROGRAM_NAME) end |
#run ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dasht/reloader.rb', line 14 def run Thread.new do while true unless changed? sleep 0.3 next end parent.log("Reloading #{$PROGRAM_NAME}...") eval(IO.read($PROGRAM_NAME)) @last_modified = File.mtime($PROGRAM_NAME) end end end |