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. It also knows the routes defined and if it contains inline templates.

Defined Under Namespace

Classes: List

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Watcher) initialize(path)

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



97
98
99
100
# File 'lib/sinatra/reloader.rb', line 97

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

Instance Attribute Details

- (Object) mtime (readonly)

Returns the value of attribute mtime



93
94
95
# File 'lib/sinatra/reloader.rb', line 93

def mtime
  @mtime
end

- (Object) path (readonly)

Returns the value of attribute path



93
94
95
# File 'lib/sinatra/reloader.rb', line 93

def path
  @path
end

- (Object) routes (readonly)

Returns the value of attribute routes



93
94
95
# File 'lib/sinatra/reloader.rb', line 93

def routes
  @routes
end

Instance Method Details

- (Object) ignore

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



126
127
128
# File 'lib/sinatra/reloader.rb', line 126

def ignore
  @ignore = true
end

- (Boolean) ignore?

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

Returns:

  • (Boolean)


132
133
134
# File 'lib/sinatra/reloader.rb', line 132

def ignore?
  !!@ignore
end

- (Object) inline_templates

Informs that the file being watched has inline templates.



114
115
116
# File 'lib/sinatra/reloader.rb', line 114

def inline_templates
  @inline_templates = true
end

- (Boolean) inline_templates?

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

Returns:

  • (Boolean)


120
121
122
# File 'lib/sinatra/reloader.rb', line 120

def inline_templates?
  !!@inline_templates
end

- (Boolean) removed?

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

Returns:

  • (Boolean)


138
139
140
# File 'lib/sinatra/reloader.rb', line 138

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

- (Object) update

Updates the file being watched mtime.



109
110
111
# File 'lib/sinatra/reloader.rb', line 109

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

- (Boolean) updated?

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

Returns:

  • (Boolean)


104
105
106
# File 'lib/sinatra/reloader.rb', line 104

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