Class: Sinatra::Reloader::FileWatcher
- Inherits:
-
Array
- Object
- Array
- Sinatra::Reloader::FileWatcher
- Extended by:
- Enumerable
- Defined in:
- lib/sinatra/reloader.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#inline_templates ⇒ Object
readonly
Returns the value of attribute inline_templates.
-
#mtime ⇒ Object
readonly
Returns the value of attribute mtime.
Class Method Summary collapse
Instance Method Summary collapse
- #changed? ⇒ Boolean
- #dont_reload!(dont = true) ⇒ Object
-
#initialize(file, app) ⇒ FileWatcher
constructor
A new instance of FileWatcher.
- #inline_templates! ⇒ Object
- #inline_templates? ⇒ Boolean
- #reload ⇒ Object
- #reload! ⇒ Object
- #reload? ⇒ Boolean
Constructor Details
#initialize(file, app) ⇒ FileWatcher
Returns a new instance of FileWatcher.
36 37 38 39 40 |
# File 'lib/sinatra/reloader.rb', line 36 def initialize(file, app) @reload, @file, @app = true, file, app @mtime = File.exist?(file) ? File.mtime(file) : Time.at(0) super() end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
11 12 13 |
# File 'lib/sinatra/reloader.rb', line 11 def app @app end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
11 12 13 |
# File 'lib/sinatra/reloader.rb', line 11 def file @file end |
#inline_templates ⇒ Object (readonly)
Returns the value of attribute inline_templates.
11 12 13 |
# File 'lib/sinatra/reloader.rb', line 11 def inline_templates @inline_templates end |
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
11 12 13 |
# File 'lib/sinatra/reloader.rb', line 11 def mtime @mtime end |
Class Method Details
.each(&block) ⇒ Object
32 33 34 |
# File 'lib/sinatra/reloader.rb', line 32 def self.each(&block) @map.values.each(&block) end |
.new(file, app) ⇒ Object Also known as: []
19 20 21 22 23 24 25 26 |
# File 'lib/sinatra/reloader.rb', line 19 def self.new(file, app) file = file. begin file = file.realpath rescue Errno::ENOENT end @map[file] ||= super end |
.register(route) ⇒ Object
15 16 17 |
# File 'lib/sinatra/reloader.rb', line 15 def self.register(route) new(route.file, route.app) << route if route.file? end |
Instance Method Details
#changed? ⇒ Boolean
42 43 44 |
# File 'lib/sinatra/reloader.rb', line 42 def changed? !File.exist? file or @mtime != File.mtime(file) end |
#dont_reload!(dont = true) ⇒ Object
46 47 48 |
# File 'lib/sinatra/reloader.rb', line 46 def dont_reload!(dont = true) @reload = !dont end |
#inline_templates! ⇒ Object
62 63 64 |
# File 'lib/sinatra/reloader.rb', line 62 def inline_templates! @inline_templates = true end |
#inline_templates? ⇒ Boolean
58 59 60 |
# File 'lib/sinatra/reloader.rb', line 58 def inline_templates? !!inline_templates end |
#reload ⇒ Object
54 55 56 |
# File 'lib/sinatra/reloader.rb', line 54 def reload reload! if reload? end |
#reload! ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/sinatra/reloader.rb', line 66 def reload! each { |route| route.deactivate } $LOADED_FEATURES.delete file clear if File.exist? file app.set :inline_templates, file if inline_templates? @mtime = File.mtime(file) require file end end |
#reload? ⇒ Boolean
50 51 52 |
# File 'lib/sinatra/reloader.rb', line 50 def reload? @reload and changed? end |