class RSpec::Raml::Finder

Attributes

raml[R]

Public Class Methods

new(raml) click to toggle source
# File lib/rspec/raml/finder.rb, line 8
def initialize(raml)
  @raml = raml
end

Public Instance Methods

find_resources(path, node = raml) click to toggle source

Recursively traverses the raml structure and locates all Raml::Resources with a matching url.

# File lib/rspec/raml/finder.rb, line 14
def find_resources(path, node = raml)
  node.children.flat_map do |child|
    if child.kind_of?(::Raml::Resource) && child.resource_path == path
      child
    elsif child.respond_to?(:children)
      find_resources(path, child)
    else
      []
    end
  end
end
find_response(verb, path, status) click to toggle source

Finds the response that matches the verb, path, and status.

# File lib/rspec/raml/finder.rb, line 27
def find_response(verb, path, status)
  resources = find_resources(path)

  resource = resources.find do |node|
    method = node.methods[verb.to_s]
    method && method.responses[status]
  end

  http_method = resource && resource.methods[verb.to_s]
  http_method.responses[status] if http_method
end