module Sinatra::Reloader::ExtensionMethods

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

Public Instance Methods

also_reload(*glob) click to toggle source

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

# File lib/ella/reloader.rb, line 381
def also_reload(*glob)
  Dir[*glob].each { |path| Watcher::List.for(self).watch_file(path) }
end
deactivate(element) click to toggle source

Removes the element from the Sinatra application.

# File lib/ella/reloader.rb, line 360
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) click to toggle source

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

# File lib/ella/reloader.rb, line 387
def dont_reload(*glob)
  Dir[*glob].each { |path| Watcher::List.for(self).ignore(path) }
end

Private Instance Methods

register_path() click to toggle source

attr_reader :register_path warn on -w (private attribute)

# File lib/ella/reloader.rb, line 394
def register_path; @register_path ||= nil; end
registering_extension?() click to toggle source

Indicates whether or not an extension is being registered.

# File lib/ella/reloader.rb, line 407
def registering_extension?
  !register_path.nil?
end
start_registering_extension() click to toggle source

Indicates an extesion is being registered.

# File lib/ella/reloader.rb, line 397
def start_registering_extension
  @register_path = caller_files[2]
end
stop_registering_extension() click to toggle source

Indicates the extesion has already been registered.

# File lib/ella/reloader.rb, line 402
def stop_registering_extension
  @register_path = nil
end
watch_element(path, type, representation=nil) click to toggle source

Builds a Watcher::Element from type and representation and tells the Watcher::List for the current application to watch it in the file located at path.

If an extension is being registered, it also tells the list to watch it in the file where the extension has been registered. This prevents the duplication of the elements added by the extension in its registered method with every reload.

# File lib/ella/reloader.rb, line 419
def watch_element(path, type, representation=nil)
  list = Watcher::List.for(self)
  element = Watcher::Element.new(type, representation)
  list.watch(path, element)
  list.watch(register_path, element) if registering_extension?
end