123456789_123456789_123456789_123456789_123456789_

Class: Sinatra::Reloader::Watcher

Relationships & Source Files
Namespace Children
Classes:
Inherits: Object
Defined in: sinatra-contrib/lib/sinatra/reloader.rb

Overview

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

Class Method Summary

Instance Attribute Summary

Instance Method Summary

  • #update

    Updates the mtime of the file being watched.

Constructor Details

.new(path) ⇒ Watcher

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

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/reloader.rb', line 175

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

Instance Attribute Details

#elements (readonly)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/reloader.rb', line 172

attr_reader :path, :elements, :mtime

#ignore (readonly)

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

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/reloader.rb', line 200

def ignore
  @ignore = true
end

#ignore?Boolean (readonly)

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

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/reloader.rb', line 206

def ignore?
  !!@ignore
end

#inline_templates?Boolean (readonly)

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

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/reloader.rb', line 194

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

#mtime (readonly)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/reloader.rb', line 172

attr_reader :path, :elements, :mtime

#path (readonly)

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/reloader.rb', line 172

attr_reader :path, :elements, :mtime

#removed?Boolean (readonly)

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

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/reloader.rb', line 211

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

#updated?Boolean (readonly)

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

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/reloader.rb', line 183

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

Instance Method Details

#update

Updates the mtime of the file being watched.

[ GitHub ]

  
# File 'sinatra-contrib/lib/sinatra/reloader.rb', line 188

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