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
- #ignored?(ignore_list) ⇒ Boolean
-
#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
51 52 53 54 55 |
# File 'lib/fitting/response.rb', line 51 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
47 48 49 |
# File 'lib/fitting/response.rb', line 47 def got JSON.pretty_generate(MultiJson.load(@body)) end |
#ignored?(ignore_list) ⇒ Boolean
57 58 59 |
# File 'lib/fitting/response.rb', line 57 def ignored?(ignore_list) @request.ignored?(ignore_list) end |
#real_request_with_status ⇒ Object
43 44 45 |
# File 'lib/fitting/response.rb', line 43 def real_request_with_status "#{@request.real_method_with_path} #{@status}" end |
#route ⇒ Object
31 32 33 34 35 |
# File 'lib/fitting/response.rb', line 31 def route index.map do |i| "#{@request.route} #{@status} #{i}" end 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
37 38 39 40 41 |
# File 'lib/fitting/response.rb', line 37 def strict_route strict_index.map do |i| "#{@request.route} #{@status} #{i}" end end |
#within_prefix?(prefix) ⇒ Boolean
15 16 17 |
# File 'lib/fitting/response.rb', line 15 def within_prefix?(prefix) @request.within_prefix?(prefix) end |