Class: Sinatra::Reloader::Watcher
- Inherits:
-
Object
- Object
- Sinatra::Reloader::Watcher
- 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
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#mtime ⇒ Object
readonly
Returns the value of attribute mtime.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#ignore ⇒ Object
Informs that the modifications to the file being watched should be ignored.
-
#ignore? ⇒ Boolean
Indicates whether or not the modifications to the file being watched should be ignored.
-
#initialize(path) ⇒ Watcher
constructor
Creates a new
Watcher
instance for the file located atpath
. -
#inline_templates? ⇒ Boolean
Indicates whether or not the file being watched has inline templates.
-
#removed? ⇒ Boolean
Indicates whether or not the file being watched has been removed.
-
#update ⇒ Object
Updates the mtime of the file being watched.
-
#updated? ⇒ Boolean
Indicates whether or not the file being watched has been modified.
Constructor Details
#initialize(path) ⇒ Watcher
Creates a new Watcher
instance for the file located at path
.
173 174 175 176 177 |
# File 'lib/sinatra/reloader.rb', line 173 def initialize(path) @ignore = nil @path, @elements = path, [] update end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
170 171 172 |
# File 'lib/sinatra/reloader.rb', line 170 def elements @elements end |
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
170 171 172 |
# File 'lib/sinatra/reloader.rb', line 170 def mtime @mtime end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
170 171 172 |
# File 'lib/sinatra/reloader.rb', line 170 def path @path end |
Instance Method Details
#ignore ⇒ Object
Informs that the modifications to the file being watched should be ignored.
197 198 199 |
# File 'lib/sinatra/reloader.rb', line 197 def ignore @ignore = true end |
#ignore? ⇒ Boolean
Indicates whether or not the modifications to the file being watched should be ignored.
203 204 205 |
# File 'lib/sinatra/reloader.rb', line 203 def ignore? !!@ignore end |
#inline_templates? ⇒ Boolean
Indicates whether or not the file being watched has inline templates.
191 192 193 |
# File 'lib/sinatra/reloader.rb', line 191 def inline_templates? elements.any? { |element| element.type == :inline_templates } end |
#removed? ⇒ Boolean
Indicates whether or not the file being watched has been removed.
208 209 210 |
# File 'lib/sinatra/reloader.rb', line 208 def removed? !File.exist?(path) end |
#update ⇒ Object
Updates the mtime of the file being watched.
185 186 187 |
# File 'lib/sinatra/reloader.rb', line 185 def update @mtime = File.mtime(path) end |
#updated? ⇒ Boolean
Indicates whether or not the file being watched has been modified.
180 181 182 |
# File 'lib/sinatra/reloader.rb', line 180 def updated? !ignore? && !removed? && mtime != File.mtime(path) end |