Module: Rack::Delegator
- Included in:
- Waw::Controller, Waw::JSONController, Waw::Kern::App, Waw::Restart
- Defined in:
- lib/waw/ext/rack/delegator.rb
Overview
Extends Rack application with utilities. This module may be included by standard rack applications delegating to another one. The later is expected to be returned by delegate. Methods are intended to be overriden for matching specific situations.
Instance Method Summary collapse
-
#_visit(path, block) ⇒ Object
Internal implementation of visit.
-
#delegate ⇒ Object
Returns delegate rack application.
-
#find_rack_app(path = nil, &block) ⇒ Object
Finds a rack application mapped to a given path.
-
#find_url_of(app) ⇒ Object
Recursively finds the URL on which a given application is installed.
-
#has_delegate? ⇒ Boolean
Checks if a delegate exists.
-
#is_delegate?(app) ⇒ Boolean
Checks if an app may be safely considered in the chain.
-
#visit(&block) ⇒ Object
Visits the Rack application tree recursively by calling the block.
Instance Method Details
#_visit(path, block) ⇒ Object
Internal implementation of visit.
45 46 47 48 |
# File 'lib/waw/ext/rack/delegator.rb', line 45 def _visit(path, block) block.call(path, self) delegate._visit(path, block) if has_delegate? end |
#delegate ⇒ Object
Returns delegate rack application. By default, returns @app.
9 10 11 |
# File 'lib/waw/ext/rack/delegator.rb', line 9 def delegate @app end |
#find_rack_app(path = nil, &block) ⇒ Object
Finds a rack application mapped to a given path. If a block is provided it is used as a predicate matcher.
25 26 27 28 |
# File 'lib/waw/ext/rack/delegator.rb', line 25 def find_rack_app(path = nil, &block) return self if (block && block.call(self)) has_delegate? ? delegate.find_rack_app(path, &block) : nil end |
#find_url_of(app) ⇒ Object
Recursively finds the URL on which a given application is installed.
31 32 33 34 |
# File 'lib/waw/ext/rack/delegator.rb', line 31 def find_url_of(app) visit{|path, visited| return path if app==visited} nil end |
#has_delegate? ⇒ Boolean
Checks if a delegate exists.
19 20 21 |
# File 'lib/waw/ext/rack/delegator.rb', line 19 def has_delegate? not(delegate.nil?) and is_delegate?(delegate) end |
#is_delegate?(app) ⇒ Boolean
Checks if an app may be safely considered in the chain
14 15 16 |
# File 'lib/waw/ext/rack/delegator.rb', line 14 def is_delegate?(app) Delegator===app end |
#visit(&block) ⇒ Object
Visits the Rack application tree recursively by calling the block. The later is expected to have two parameters |path,app|. The first one is an array containing url components, the second is the visited application.
40 41 42 |
# File 'lib/waw/ext/rack/delegator.rb', line 40 def visit(&block) _visit("/", block) end |