Class: Rack::Raml::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/raml/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raml_file, request) ⇒ Response

Returns a new instance of Response.



9
10
11
12
# File 'lib/rack/raml/response.rb', line 9

def initialize(raml_file, request)
  @raml = ::Raml.parse_file(raml_file)
  @request = request
end

Instance Attribute Details

#ramlObject (readonly)

Returns the value of attribute raml.



7
8
9
# File 'lib/rack/raml/response.rb', line 7

def raml
  @raml
end

#requestObject (readonly)

Returns the value of attribute request.



7
8
9
# File 'lib/rack/raml/response.rb', line 7

def request
  @request
end

Instance Method Details

#matches?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/rack/raml/response.rb', line 14

def matches?
  !response.nil?
end

#to_rackObject



18
19
20
21
22
23
24
# File 'lib/rack/raml/response.rb', line 18

def to_rack
  if matches?
    [code, { 'Content-Type' => type }, [body]]
  else
    [404, { 'Content-Type' => type }, [not_found]]
  end
end