Class: BigBand::Reloader::FileWatcher
- Inherits:
-
Array
- Object
- Array
- BigBand::Reloader::FileWatcher
- Extended by:
- Enumerable
- Defined in:
- lib/big_band/reloader.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#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) ⇒ FileWatcher
constructor
A new instance of FileWatcher.
- #reload ⇒ Object
- #reload! ⇒ Object
- #reload? ⇒ Boolean
Constructor Details
#initialize(file) ⇒ FileWatcher
Returns a new instance of FileWatcher.
44 45 46 47 48 |
# File 'lib/big_band/reloader.rb', line 44 def initialize(file) @reload = true @file, @mtime = file, File.mtime(file) super() end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
27 28 29 |
# File 'lib/big_band/reloader.rb', line 27 def file @file end |
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
27 28 29 |
# File 'lib/big_band/reloader.rb', line 27 def mtime @mtime end |
Class Method Details
.each(&block) ⇒ Object
40 41 42 |
# File 'lib/big_band/reloader.rb', line 40 def self.each(&block) @map.values.each(&block) end |
.new(file) ⇒ Object
36 37 38 |
# File 'lib/big_band/reloader.rb', line 36 def self.new(file) @map[file.] ||= super(file) end |
.register(route) ⇒ Object
32 33 34 |
# File 'lib/big_band/reloader.rb', line 32 def self.register(route) new(route.file) << route if route.file? end |
Instance Method Details
#changed? ⇒ Boolean
50 51 52 |
# File 'lib/big_band/reloader.rb', line 50 def changed? @mtime != File.mtime(file) end |
#dont_reload!(dont = true) ⇒ Object
54 55 56 |
# File 'lib/big_band/reloader.rb', line 54 def dont_reload!(dont = true) @reload = false end |
#reload ⇒ Object
62 63 64 |
# File 'lib/big_band/reloader.rb', line 62 def reload reload! if reload? end |
#reload! ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/big_band/reloader.rb', line 66 def reload! puts "reloading #{file}" each { |route| route.deactivate } $LOAD_PATH.delete file $LOAD_PATH.delete file. clear require file end |
#reload? ⇒ Boolean
58 59 60 |
# File 'lib/big_band/reloader.rb', line 58 def reload? @reload and changed? end |