Class: Fitting::Response
- Inherits:
-
Object
- Object
- Fitting::Response
- Defined in:
- lib/fitting/response.rb,
lib/fitting/response/fully_validates.rb
Defined Under Namespace
Classes: FullyValidates
Instance Method Summary collapse
- #documented? ⇒ Boolean
- #expected ⇒ Object
- #fully_validates ⇒ Object
- #got ⇒ Object
-
#initialize(env_response, tomogram) ⇒ Response
constructor
A new instance of Response.
- #real_request_with_status ⇒ Object
- #route ⇒ Object
- #strict_fully_validates ⇒ Object
- #strict_route ⇒ Object
- #within_prefix?(prefix) ⇒ Boolean
Constructor Details
#initialize(env_response, tomogram) ⇒ Response
Returns a new instance of Response.
8 9 10 11 12 13 |
# File 'lib/fitting/response.rb', line 8 def initialize(env_response, tomogram) @request = Fitting::Request.new(env_response.request, tomogram) @status = env_response.status @body = env_response.body @schemas = @request.schemas_of_possible_responses(status: @status) end |
Instance Method Details
#documented? ⇒ Boolean
27 28 29 |
# File 'lib/fitting/response.rb', line 27 def documented? @schemas && @schemas.present? end |
#expected ⇒ Object
47 48 49 50 51 |
# File 'lib/fitting/response.rb', line 47 def expected @expected ||= @schemas.inject([]) do |res, schema| res.push(JSON.pretty_generate(schema).to_s) end.join("\n\n") end |
#fully_validates ⇒ Object
19 20 21 |
# File 'lib/fitting/response.rb', line 19 def fully_validates @fully_validates ||= Fitting::Response::FullyValidates.craft(@schemas, @body, false) end |
#got ⇒ Object
43 44 45 |
# File 'lib/fitting/response.rb', line 43 def got JSON.pretty_generate(MultiJson.load(@body)) end |
#real_request_with_status ⇒ Object
39 40 41 |
# File 'lib/fitting/response.rb', line 39 def real_request_with_status "#{@request.real_method_with_path} #{@status}" end |
#route ⇒ Object
31 32 33 |
# File 'lib/fitting/response.rb', line 31 def route "#{@request.route} #{@status} #{index}" end |
#strict_fully_validates ⇒ Object
23 24 25 |
# File 'lib/fitting/response.rb', line 23 def strict_fully_validates @strict_fully_validates ||= Fitting::Response::FullyValidates.craft(@schemas, @body, true) end |
#strict_route ⇒ Object
35 36 37 |
# File 'lib/fitting/response.rb', line 35 def strict_route "#{@request.route} #{@status} #{strict_index}" end |
#within_prefix?(prefix) ⇒ Boolean
15 16 17 |
# File 'lib/fitting/response.rb', line 15 def within_prefix?(prefix) @request.within_prefix?(prefix) end |