Class: Rack::FileWatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/file_watcher.rb,
lib/rack/file_watcher/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Constructor Details

#initialize(app, file_path, &block) ⇒ FileWatcher

Returns a new instance of FileWatcher.



6
7
8
9
10
11
12
13
14
# File 'lib/rack/file_watcher.rb', line 6

def initialize(app, file_path, &block)
  @app = app
  @file_path = file_path
  @block = block

  initialize_target_file

  @last_update_at = updated_at
end

Instance Method Details

#call(env) ⇒ Object



25
26
27
28
29
# File 'lib/rack/file_watcher.rb', line 25

def call(env)
  execute_if_updated

  @app.call(env)
end

#execute_if_updatedObject



16
17
18
19
20
21
22
23
# File 'lib/rack/file_watcher.rb', line 16

def execute_if_updated
  current_updated_at = updated_at

  if @last_update_at != current_updated_at
    @block.call
    @last_update_at = current_updated_at
  end
end