Class: OpenapiBlocks::FileWatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_blocks/file_watcher.rb

Overview

rubocop:disable Style/Documentation

Constant Summary collapse

WATCH_PATTERNS =
[
  "app/openapi/**/*.rb",
  "app/models/**/*.rb",
  "config/routes.rb",
  "db/schema.rb"
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(root_path) ⇒ FileWatcher

Returns a new instance of FileWatcher.



12
13
14
15
16
# File 'lib/openapi_blocks/file_watcher.rb', line 12

def initialize(root_path)
  @root_path = root_path
  @mtimes    = {}
  snapshot!
end

Instance Method Details

#snapshot!Object



24
25
26
27
28
# File 'lib/openapi_blocks/file_watcher.rb', line 24

def snapshot!
  watched_files.each do |file|
    @mtimes[file] = mtime(file)
  end
end

#stale?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/openapi_blocks/file_watcher.rb', line 18

def stale?
  watched_files.any? do |file|
    mtime(file) != @mtimes[file]
  end
end