Class: RbReloader::FileWatcher
- Inherits:
-
Array
- Object
- Array
- RbReloader::FileWatcher
- Defined in:
- lib/rb_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
- .each(&block) ⇒ Object
- .new(file) ⇒ Object (also: [])
Instance Method Summary collapse
- #changed? ⇒ Boolean
-
#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.
20 21 22 23 24 |
# File 'lib/rb_reloader.rb', line 20 def initialize(file) @reload, @file = true, file @mtime = File.exist?(file) ? File.mtime(file) : Time.at(0) super() end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
5 6 7 |
# File 'lib/rb_reloader.rb', line 5 def file @file end |
#mtime ⇒ Object (readonly)
Returns the value of attribute mtime.
5 6 7 |
# File 'lib/rb_reloader.rb', line 5 def mtime @mtime end |
Class Method Details
.each(&block) ⇒ Object
16 17 18 |
# File 'lib/rb_reloader.rb', line 16 def self.each(&block) @map.values.each(&block) end |
.new(file) ⇒ Object Also known as: []
8 9 10 |
# File 'lib/rb_reloader.rb', line 8 def self.new(file) @map[file] ||= super end |
Instance Method Details
#changed? ⇒ Boolean
30 31 32 |
# File 'lib/rb_reloader.rb', line 30 def changed? !File.exist? file or @mtime != File.mtime(file) end |
#reload ⇒ Object
34 35 36 |
# File 'lib/rb_reloader.rb', line 34 def reload reload! if reload? end |
#reload! ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/rb_reloader.rb', line 38 def reload! $LOADED_FEATURES.delete file clear if File.exist? file @mtime = File.mtime(file) require file end end |
#reload? ⇒ Boolean
26 27 28 |
# File 'lib/rb_reloader.rb', line 26 def reload? @reload and changed? end |