Class: Sinatra::Reloader::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/ella/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.



186
187
188
189
190
# File 'lib/ella/reloader.rb', line 186

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

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements.



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

def elements
  @elements
end

#mtimeObject (readonly)

Returns the value of attribute mtime.



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

def mtime
  @mtime
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#ignoreObject

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



210
211
212
# File 'lib/ella/reloader.rb', line 210

def ignore
  @ignore = true
end

#ignore?Boolean

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



216
217
218
# File 'lib/ella/reloader.rb', line 216

def ignore?
  !!@ignore
end

#inline_templates?Boolean

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



204
205
206
# File 'lib/ella/reloader.rb', line 204

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

#removed?Boolean

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



221
222
223
# File 'lib/ella/reloader.rb', line 221

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

#updateObject

Updates the mtime of the file being watched.



198
199
200
# File 'lib/ella/reloader.rb', line 198

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

#updated?Boolean

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



193
194
195
# File 'lib/ella/reloader.rb', line 193

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