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 contains.

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.



152
153
154
155
# File 'lib/sinatra/reloader.rb', line 152

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

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements.



149
150
151
# File 'lib/sinatra/reloader.rb', line 149

def elements
  @elements
end

#mtimeObject (readonly)

Returns the value of attribute mtime.



149
150
151
# File 'lib/sinatra/reloader.rb', line 149

def mtime
  @mtime
end

#pathObject (readonly)

Returns the value of attribute path.



149
150
151
# File 'lib/sinatra/reloader.rb', line 149

def path
  @path
end

Instance Method Details

#ignoreObject

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



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

def ignore
  @ignore = true
end

#ignore?Boolean

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

Returns:

  • (Boolean)


181
182
183
# File 'lib/sinatra/reloader.rb', line 181

def ignore?
  !!@ignore
end

#inline_templates?Boolean

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

Returns:

  • (Boolean)


169
170
171
# File 'lib/sinatra/reloader.rb', line 169

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)


186
187
188
# File 'lib/sinatra/reloader.rb', line 186

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

#updateObject

Updates the file being watched mtime.



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

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

#updated?Boolean

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

Returns:

  • (Boolean)


158
159
160
# File 'lib/sinatra/reloader.rb', line 158

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