Class: Sinatra::Reloader::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/reloader.rb

Overview

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

Defined Under Namespace

Classes: Element, List

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Watcher

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



166
167
168
169
170
# File 'lib/sinatra/reloader.rb', line 166

def initialize(path)
  @ignore = nil
  @path, @elements = path, []
  update
end

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements



163
164
165
# File 'lib/sinatra/reloader.rb', line 163

def elements
  @elements
end

#mtimeObject (readonly)

Returns the value of attribute mtime



163
164
165
# File 'lib/sinatra/reloader.rb', line 163

def mtime
  @mtime
end

#pathObject (readonly)

Returns the value of attribute path



163
164
165
# File 'lib/sinatra/reloader.rb', line 163

def path
  @path
end

Instance Method Details

#ignoreObject

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



190
191
192
# File 'lib/sinatra/reloader.rb', line 190

def ignore
  @ignore = true
end

#ignore?Boolean

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



196
197
198
# File 'lib/sinatra/reloader.rb', line 196

def ignore?
  !!@ignore
end

#inline_templates?Boolean

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



184
185
186
# File 'lib/sinatra/reloader.rb', line 184

def inline_templates?
  elements.any? { |element| element.type == :inline_templates }
end

#removed?Boolean

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



201
202
203
# File 'lib/sinatra/reloader.rb', line 201

def removed?
  !File.exist?(path)
end

#updateObject

Updates the mtime of the file being watched.



178
179
180
# File 'lib/sinatra/reloader.rb', line 178

def update
  @mtime = File.mtime(path)
end

#updated?Boolean

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



173
174
175
# File 'lib/sinatra/reloader.rb', line 173

def updated?
  !ignore? && !removed? && mtime != File.mtime(path)
end