Class: Orbit::Loaders::FileReloader

Inherits:
Object
  • Object
show all
Defined in:
lib/orbit/loaders/file_reloader.rb

Instance Method Summary collapse

Constructor Details

#initialize(files) ⇒ FileReloader

Returns a new instance of FileReloader.



4
5
6
7
8
# File 'lib/orbit/loaders/file_reloader.rb', line 4

def initialize(files)
  @files = files
  @last_updated = {}
  set_last_updated_dates
end

Instance Method Details

#reloadObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/orbit/loaders/file_reloader.rb', line 16

def reload
  @files.each do |file|
    was_updated = File.mtime(file).to_i > @last_updated[file]

    if was_updated
      p "reloading #{file}"
      
      load file
      @last_updated[file] = File.mtime(file).to_i
    end
  end
end

#set_last_updated_datesObject



10
11
12
13
14
# File 'lib/orbit/loaders/file_reloader.rb', line 10

def set_last_updated_dates
  @files.each do |file|
    @last_updated[file] = File.mtime(file).to_i
  end
end