Module: Waw::Routing::Methods
- Included in:
- Waw::Routing
- Defined in:
- lib/waw/routing.rb
Instance Method Summary collapse
-
#matches?(what, json_response = self) ⇒ Boolean
(also: #=~)
Checks if a service response matches some expected pattern.
Instance Method Details
#matches?(what, json_response = self) ⇒ Boolean Also known as: =~
Checks if a service response matches some expected pattern
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/waw/routing.rb', line 14 def matches?(what, json_response = self) raise ArgumentError, "Array expected as json_response (#{json_response.inspect} found)" unless Array===json_response json_response = json_response.dup what.split('/').each do |elm| return false if json_response.empty? case part = json_response.shift when String, Symbol if elm == '*' # always ok here else return false unless part.to_s==elm.to_s end when Array if elm == '*' return false if part.empty? else return false unless part.any?{|e| e.to_s == elm.to_s} or (elm=='*') end else raise ArgumentError, "Unexpected part in json_response #{part}" end end true end |