Class: Waves::Matchers::URI
Overview
Matcher for the whole URL.
Instance Attribute Summary collapse
-
#constraints ⇒ Object
Returns the value of attribute constraints.
Instance Method Summary collapse
-
#[](request) ⇒ Object
Proc-like interface.
-
#call(request) ⇒ Object
Match resource URL.
-
#initialize(options) ⇒ URI
constructor
A new instance of URI.
- #test(request) ⇒ Object
Constructor Details
#initialize(options) ⇒ URI
Returns a new instance of URI.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/waves/matchers/uri.rb', line 11 def initialize() # Simplest to fake it if there is no path to match @path = if [:path] Waves::Matchers::Path.new( [:path] ) else lambda { {} } end @constraints = {} @constraints[:host] = [:host] if [:host] @constraints[:port] = [:port] if [:port] @constraints[:scheme] = [:scheme] if [:scheme] raise ArgumentError, "No URI matching" if !@path and @constraints.empty? end |
Instance Attribute Details
#constraints ⇒ Object
Returns the value of attribute constraints.
9 10 11 |
# File 'lib/waves/matchers/uri.rb', line 9 def constraints @constraints end |
Instance Method Details
#[](request) ⇒ Object
Proc-like interface
60 61 62 |
# File 'lib/waves/matchers/uri.rb', line 60 def [](request) call request end |
#call(request) ⇒ Object
Match resource URL.
This returns the set of captures if matching!
33 34 35 36 37 |
# File 'lib/waves/matchers/uri.rb', line 33 def call(request) if captures = @path.call(request) and test(request) captures end end |
#test(request) ⇒ Object
TODO:
This could maybe be optimised by detecting empty constraints before calling. Not high importance. –rue
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/waves/matchers/uri.rb', line 44 def test(request) constraints.all? {|key, val| if val.nil? or val == true true else if val.respond_to? :call val.call( request ) else val == request.send( key ) or val === request.send( key ) or request.send( key ) === val end end } end |