Module: Sinatra::Reloader::ExtensionMethods
Relationships & Source Files | |
Defined in: | sinatra-contrib/lib/sinatra/reloader.rb |
Overview
Contains the methods that the extension adds to the ::Sinatra
application.
Instance Attribute Summary
-
#registering_extension? ⇒ Boolean
readonly
private
Indicates whether or not an extension is being registered.
Instance Method Summary
-
#also_reload(*glob)
Indicates with a
glob
which files should be reloaded if they have been modified. -
#deactivate(element)
Removes the
element
from the::Sinatra
application. -
#dont_reload(*glob)
Indicates with a
glob
which files should not be reloaded even if they have been modified. -
#register_path
private
attr_reader
:register_path
warn on -w (private attribute). -
#start_registering_extension
private
Indicates an extension is being registered.
-
#stop_registering_extension
private
Indicates the extension has already been registered.
-
#watch_element(path, type, representation = nil)
private
Builds a
Watcher::Element
fromtype
andrepresentation
and tells theWatcher::List
for the current application to watch it in the file located atpath
.
Instance Attribute Details
#registering_extension? ⇒ Boolean
(readonly, private)
Indicates whether or not an extension is being registered.
# File 'sinatra-contrib/lib/sinatra/reloader.rb', line 409
def registering_extension? !register_path.nil? end
Instance Method Details
#also_reload(*glob)
Indicates with a glob
which files should be reloaded if they
have been modified. It can be called several times.
#deactivate(element)
Removes the element
from the ::Sinatra
application.
# File 'sinatra-contrib/lib/sinatra/reloader.rb', line 362
def deactivate(element) case element.type when :route verb = element.representation[:verb] signature = element.representation[:signature] (routes[verb] ||= []).delete(signature) when :middleware @middleware.delete(element.representation) when :before_filter filters[:before].delete(element.representation) when :after_filter filters[:after].delete(element.representation) when :error code = element.representation[:code] handler = element.representation[:handler] @errors.delete(code) if @errors[code] == handler end end
#dont_reload(*glob)
Indicates with a glob
which files should not be reloaded even if
they have been modified. It can be called several times.
#register_path (private)
attr_reader :register_path
warn on -w (private attribute)
# File 'sinatra-contrib/lib/sinatra/reloader.rb', line 396
def register_path; @register_path ||= nil; end
#start_registering_extension (private)
Indicates an extension is being registered.
# File 'sinatra-contrib/lib/sinatra/reloader.rb', line 399
def start_registering_extension @register_path = caller_files[2] end
#stop_registering_extension (private)
Indicates the extension has already been registered.
# File 'sinatra-contrib/lib/sinatra/reloader.rb', line 404
def stop_registering_extension @register_path = nil end
#watch_element(path, type, representation = nil) (private)
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 Sinatra::Reloader.registered method with every reload.
# File 'sinatra-contrib/lib/sinatra/reloader.rb', line 421
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