Module: Sinatra::Reloader::ExtensionMethods

Defined in:
lib/sinatra/reloader.rb

Overview

Contains the methods that the extension adds to the Sinatra application.

Instance Method Summary collapse

Instance Method Details

#also_reload(*glob) ⇒ Object

Indicates with a glob which files should be reloaded if they have been modified. It can be called several times.



346
347
348
# File 'lib/sinatra/reloader.rb', line 346

def also_reload(*glob)
  Dir[*glob].each { |path| Watcher::List.for(self).watch_file(path) }
end

#deactivate(element) ⇒ Object

Removes the element from the Sinatra application.



325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/sinatra/reloader.rb', line 325

def deactivate(element)
  case element.type
  when :route then
    verb      = element.representation[:verb]
    signature = element.representation[:signature]
    (routes[verb] ||= []).delete(signature)
  when :middleware then
    @middleware.delete(element.representation)
  when :before_filter then
    filters[:before].delete(element.representation)
  when :after_filter then
    filters[:after].delete(element.representation)
  when :error then
    code    = element.representation[:code]
    handler = element.representation[:handler]
    @errors.delete(code) if @errors[code] == handler
  end
end

#dont_reload(*glob) ⇒ Object

Indicates with a glob which files should not be reloaded even if they have been modified. It can be called several times.



352
353
354
# File 'lib/sinatra/reloader.rb', line 352

def dont_reload(*glob)
  Dir[*glob].each { |path| Watcher::List.for(self).ignore(path) }
end