Class: Dasht::Reloader

Inherits:
Object
  • Object
show all
Defined in:
lib/dasht/reloader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#parentObject

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

Returns:

  • (Boolean)


10
11
12
# File 'lib/dasht/reloader.rb', line 10

def changed?
  @last_modified != File.mtime($PROGRAM_NAME)
end

#runObject



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