class Sinatra::Reloader::Watcher

Watches a file so it can tell when it has been updated, and what elements contains.

Attributes

elements[R]
mtime[R]
path[R]

Public Class Methods

new(path) click to toggle source

Creates a new Watcher instance for the file located at path.

# File lib/sinatra/reloader.rb, line 152
def initialize(path)
  @path, @elements = path, []
  update
end

Public Instance Methods

ignore() click to toggle source

Informs that the modifications to the file being watched should be ignored.

# File lib/sinatra/reloader.rb, line 175
def ignore
  @ignore = true
end
ignore?() click to toggle source

Indicates whether or not the modifications to the file being watched should be ignored.

# File lib/sinatra/reloader.rb, line 181
def ignore?
  !!@ignore
end
inline_templates?() click to toggle source

Indicates whether or not the file being watched has inline templates.

# File lib/sinatra/reloader.rb, line 169
def inline_templates?
  elements.any? { |element| element.type == :inline_templates }
end
removed?() click to toggle source

Indicates whether or not the file being watched has been removed.

# File lib/sinatra/reloader.rb, line 186
def removed?
  !File.exist?(path)
end
update() click to toggle source

Updates the file being watched mtime.

# File lib/sinatra/reloader.rb, line 163
def update
  @mtime = File.mtime(path)
end
updated?() click to toggle source

Indicates whether or not the file being watched has been modified.

# File lib/sinatra/reloader.rb, line 158
def updated?
  !ignore? && !removed? && mtime != File.mtime(path)
end