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.



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

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

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements.



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

def elements
  @elements
end

#mtimeObject (readonly)

Returns the value of attribute mtime.



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

def mtime
  @mtime
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#ignoreObject

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



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

def ignore
  @ignore = true
end

#ignore?Boolean

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

Returns:

  • (Boolean)


206
207
208
# File 'lib/sinatra/reloader.rb', line 206

def ignore?
  !!@ignore
end

#inline_templates?Boolean

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

Returns:

  • (Boolean)


194
195
196
# File 'lib/sinatra/reloader.rb', line 194

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

#removed?Boolean

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

Returns:

  • (Boolean)


211
212
213
# File 'lib/sinatra/reloader.rb', line 211

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

#updateObject

Updates the mtime of the file being watched.



188
189
190
# File 'lib/sinatra/reloader.rb', line 188

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

#updated?Boolean

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

Returns:

  • (Boolean)


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

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