Class: BigBand::Reloader::FileWatcher

Inherits:
Array
  • Object
show all
Extended by:
Enumerable
Defined in:
lib/big_band/reloader.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#fileObject (readonly)

Returns the value of attribute file.



27
28
29
# File 'lib/big_band/reloader.rb', line 27

def file
  @file
end

#mtimeObject (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.expand_path] ||= 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

Returns:

  • (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

#reloadObject



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.expand_path
  clear
  require file
end

#reload?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/big_band/reloader.rb', line 58

def reload?
  @reload and changed?
end