Class: Waves::Matchers::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/waves/matchers/query.rb

Overview

Query parameter matching.

Instance Method Summary collapse

Constructor Details

#initialize(pattern) ⇒ Query

TODO:

Should map Symbols to Strings here. –rue

Create query matcher or fail.

Raises:

  • (ArgumentError)


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