Method: ApiResource::Mocks.matching

Defined in:
lib/api_resource/mocks.rb

.matching(path) ⇒ Object

returns a hash => [[Request, Response],], :params => {…} if there is no match returns nil



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/api_resource/mocks.rb', line 83

def self.matching(path)
  # The obvious case
  if @@endpoints[path]
    return {:responses => @@endpoints[path], :params => {}}
  end
  # parameter names prefixed with colons should match parts
  # of the path and push those parameters into the response
  @@endpoints.keys.each do |possible_path|
    if self.paths_match?(possible_path, path)
      return {:responses => @@endpoints[possible_path], :params => self.extract_params(possible_path, path)}
    end
  end

  return {:responses => nil, :params => nil}
end