Class: James::Reloader

Inherits:
Monk::Glue::Reloader
  • Object
show all
Defined in:
lib/james/reloader.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.filesObject



45
46
47
48
49
50
51
52
53
# File 'lib/james/reloader.rb', line 45

def files
  array = []
  James.libs.each do |dir, reload|
    file = dir.sub(/(\.rb)?$/, '') + '.rb'
    array << file if File.exist?(file)
    array.concat(Dir.glob("#{dir}/**/*.rb").sort) if File.directory?(dir)
  end
  return array
end

.reload!Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/james/reloader.rb', line 14

def reload!
  updated_files = []
  @timestamps ||= {}
  routing_changed = false

  files.each do |file|
    begin
      now = File.mtime(file).to_i
      old = @timestamps[file].to_i
      routing = file =~ %r{(^|/)app/routes/}o
      if routing or now > old
        updated_files << file
        routing_changed = true if routing and now > old
        James.say_status(:updated, file) if now > old and old > 0
      end
      @timestamps[file] = now
    rescue Exception
      updated_files << file
    end
  end

  if routing_changed
    Main.reset!
  end

  updated_files.each do |file|
    next if !routing_changed and file =~ %r{(^|/)app/routes/}o
    load file
  end
end

Instance Method Details

#filesObject



9
10
11
# File 'lib/james/reloader.rb', line 9

def files
  self.class.files
end

#reload!Object



5
6
7
# File 'lib/james/reloader.rb', line 5

def reload!
  self.class.reload!
end