Class: Sinatra::Reloader::Watcher::List

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/reloader.rb

Overview

Collection of file Watcher that can be associated with a Sinatra application. That way, we can know which files belong to a given application and which files have been modified. It also provides a mechanism to inform a Watcher of the elements defined in the file being watched and if its changes should be ignored.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeList

Creates a new List instance.



124
125
126
127
128
# File 'lib/sinatra/reloader.rb', line 124

def initialize
  @path_watcher_map = Hash.new do |hash, key|
    hash[key] = Watcher.new(key)
  end
end

Class Method Details

.for(app) ⇒ Object

Returns the List for the application app.



119
120
121
# File 'lib/sinatra/reloader.rb', line 119

def self.for(app)
  @app_list_map[app]
end

Instance Method Details

#ignore(path) ⇒ Object

Tells the Watcher for the file located at path to ignore the file changes, and adds the Watcher to the List, if it isn’t already there.



140
141
142
# File 'lib/sinatra/reloader.rb', line 140

def ignore(path)
  watcher_for(path).ignore
end

#updatedObject

Returns an array with all the watchers in the List that have been updated.



158
159
160
# File 'lib/sinatra/reloader.rb', line 158

def updated
  watchers.find_all(&:updated?)
end

#watch(path, element) ⇒ Object

Lets the Watcher for the file located at path know that the element is defined there, and adds the Watcher to the List, if it isn’t already there.



133
134
135
# File 'lib/sinatra/reloader.rb', line 133

def watch(path, element)
  watcher_for(path).elements << element
end

#watcher_for(path) ⇒ Object Also known as: watch_file

Adds a Watcher for the file located at path to the List, if it isn’t already there.



146
147
148
# File 'lib/sinatra/reloader.rb', line 146

def watcher_for(path)
  @path_watcher_map[File.expand_path(path)]
end

#watchersObject

Returns an array with all the watchers in the List.



152
153
154
# File 'lib/sinatra/reloader.rb', line 152

def watchers
  @path_watcher_map.values
end