Class: Swee::Reloader

Inherits:
Object show all
Defined in:
lib/swee/middlewaves/reloader.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, logger) ⇒ Reloader

Returns a new instance of Reloader.



5
6
7
8
9
# File 'lib/swee/middlewaves/reloader.rb', line 5

def initialize(app,logger)
  @app = app
  @logger = logger
  app_path = ENV["app_path"]
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/swee/middlewaves/reloader.rb', line 11

def call(env)
  # 快速遍历 文件 mtime cache表
  # mtime不一致则重新 load
  Lodder.mtime_files.each_pair do |file,omtime|
    mtime = File.mtime(file)
    if mtime != omtime
      load file
      Lodder.mtime_files[file] = mtime
      @logger << "#{file}文件已重载!"
    end
  end
  return @app.call(env)
end