Class: RSpec::Raml::Finder

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/raml/finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raml) ⇒ Finder

Returns a new instance of Finder.



8
9
10
# File 'lib/rspec/raml/finder.rb', line 8

def initialize(raml)
  @raml = raml
end

Instance Attribute Details

#ramlObject (readonly)

Returns the value of attribute raml.



6
7
8
# File 'lib/rspec/raml/finder.rb', line 6

def raml
  @raml
end

Instance Method Details

#find_resources(path, node = raml) ⇒ Object

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



14
15
16
17
18
19
20
21
22
23
24
# 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) ⇒ Object

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



27
28
29
30
31
32
33
34
35
36
37
# 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