Class: VResource::FileSystemReloader
- Defined in:
- lib/vresource/file_system_reloader.rb
Instance Attribute Summary collapse
-
#directories ⇒ Object
Returns the value of attribute directories.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#thread ⇒ Object
Returns the value of attribute thread.
Instance Method Summary collapse
- #check ⇒ Object
-
#initialize(directories = Dir.glob("**/lib"), interval = 2) ⇒ FileSystemReloader
constructor
A new instance of FileSystemReloader.
- #remember_file(path) ⇒ Object
- #reset ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(directories = Dir.glob("**/lib"), interval = 2) ⇒ FileSystemReloader
Returns a new instance of FileSystemReloader.
5 6 7 8 |
# File 'lib/vresource/file_system_reloader.rb', line 5 def initialize directories = Dir.glob("**/lib"), interval = 2 @files = {} self.directories, self.interval = directories, interval end |
Instance Attribute Details
#directories ⇒ Object
Returns the value of attribute directories.
3 4 5 |
# File 'lib/vresource/file_system_reloader.rb', line 3 def directories @directories end |
#interval ⇒ Object
Returns the value of attribute interval.
3 4 5 |
# File 'lib/vresource/file_system_reloader.rb', line 3 def interval @interval end |
#thread ⇒ Object
Returns the value of attribute thread.
3 4 5 |
# File 'lib/vresource/file_system_reloader.rb', line 3 def thread @thread end |
Instance Method Details
#check ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vresource/file_system_reloader.rb', line 30 def check reset if @files.empty? begin check_for_changed_files.each do |type, klass, res| VResource.notify_observers :update_resource, type, klass, res end rescue Exception => e warn e end end |
#remember_file(path) ⇒ Object
26 27 28 |
# File 'lib/vresource/file_system_reloader.rb', line 26 def remember_file path @files[path] = File.mtime(path) end |
#reset ⇒ Object
42 43 44 45 46 47 |
# File 'lib/vresource/file_system_reloader.rb', line 42 def reset @files = {} all_files.each do |path| remember_file path end end |
#start ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/vresource/file_system_reloader.rb', line 10 def start self.thread = Thread.new do while true sleep interval check end end end |
#stop ⇒ Object
19 20 21 22 23 24 |
# File 'lib/vresource/file_system_reloader.rb', line 19 def stop if thread thread.kill self.thread = nil end end |