Class: Waves::Matchers::Request
Instance Attribute Summary collapse
-
#constraints ⇒ Object
Returns the value of attribute constraints.
Instance Method Summary collapse
-
#[](request) ⇒ Object
Proc-like interface.
-
#call(request) ⇒ Object
Process all matchers for request.
-
#initialize(options) ⇒ Request
constructor
A new instance of Request.
- #test(request) ⇒ Object
Constructor Details
#initialize(options) ⇒ Request
TODO:
Further optimise the cases where there are no constraints. –rue
Returns a new instance of Request.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/waves/matchers/request.rb', line 14 def initialize() @uri = Matchers::URI.new( ) @constraints = {} if [ :requested ] @constraints[ :requested ] = Matchers::Requested.new( [ :requested ] ) end if .key?( :accept ) || .key?( :lang ) || .key?( :charset ) @constraints[:accept] = Matchers::Accept.new( ) end if .key?( :ext ) @constraints[ :ext ] = Matchers::Ext.new( [ :ext ] ) elsif .key?( :extension ) @constraints[ :ext ] = Matchers::Ext.new( [ :extension ] ) end if .key?( :query ) @constraints[:query] = Matchers::Query.new( [:query] ) end if [ :traits ] @constraints[ :traits ] = Matchers::Traits.new( [ :traits ] ) end if [ :when ] @constraints[ :when ] = [ :when ] end end |
Instance Attribute Details
#constraints ⇒ Object
Returns the value of attribute constraints.
6 7 8 |
# File 'lib/waves/matchers/request.rb', line 6 def constraints @constraints end |
Instance Method Details
#[](request) ⇒ Object
Proc-like interface
78 79 80 |
# File 'lib/waves/matchers/request.rb', line 78 def [](request) call request end |
#call(request) ⇒ Object
Process all matchers for request.
50 51 52 53 54 |
# File 'lib/waves/matchers/request.rb', line 50 def call(request) if captured = @uri.call(request) and test(request) request.traits.waves.captured = captured end end |
#test(request) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/waves/matchers/request.rb', line 61 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 |