Class: Waves::Matchers::Query
Overview
Query parameter matching.
Instance Method Summary collapse
-
#[](request) ⇒ Object
Proc-like interface.
-
#call(request) ⇒ Object
Match query parameters.
-
#initialize(pattern) ⇒ Query
constructor
Create query matcher or fail.
Constructor Details
#initialize(pattern) ⇒ Query
TODO:
Should map Symbols to Strings here. –rue
Create query matcher or fail.
13 14 15 16 |
# File 'lib/waves/matchers/query.rb', line 13 def initialize(pattern) raise ArgumentError, "No Query constraints!" unless pattern @pattern = pattern end |
Instance Method Details
#[](request) ⇒ Object
Proc-like interface
34 35 36 |
# File 'lib/waves/matchers/query.rb', line 34 def [](request) call request end |
#call(request) ⇒ Object
Match query parameters.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/waves/matchers/query.rb', line 20 def call(request) @pattern.all? {|key, val| # @todo Is this right? I do not see how even a # Proc would be useful just given nil from # a nonexisting key. We just fail in those # cases for now. --rue if given = request.query[key.to_s] val == true or val === given or (val.call(given) rescue false) end } end |