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 Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
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.
- #json_schema ⇒ Object
- #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.
9 10 11 12 13 14 |
# File 'lib/fitting/response.rb', line 9 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 Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/fitting/response.rb', line 7 def body @body end |
Instance Method Details
#documented? ⇒ Boolean
28 29 30 |
# File 'lib/fitting/response.rb', line 28 def documented? @schemas&.present? end |
#expected ⇒ Object
52 53 54 55 56 |
# File 'lib/fitting/response.rb', line 52 def expected @expected ||= @schemas.inject([]) do |res, schema| res.push(JSON.pretty_generate(schema).to_s) end.join("\n\n") end |
#fully_validates ⇒ Object
20 21 22 |
# File 'lib/fitting/response.rb', line 20 def fully_validates @fully_validates ||= Fitting::Response::FullyValidates.craft(@schemas, @body, false) end |
#got ⇒ Object
48 49 50 |
# File 'lib/fitting/response.rb', line 48 def got JSON.pretty_generate(JSON.parse(@body)) end |
#ignored?(ignore_list) ⇒ Boolean
62 63 64 |
# File 'lib/fitting/response.rb', line 62 def ignored?(ignore_list) @request.ignored?(ignore_list) end |
#json_schema ⇒ Object
58 59 60 |
# File 'lib/fitting/response.rb', line 58 def json_schema @schemas[index.first] end |
#real_request_with_status ⇒ Object
44 45 46 |
# File 'lib/fitting/response.rb', line 44 def real_request_with_status "#{@request.real_method_with_path} #{@status}" end |
#route ⇒ Object
32 33 34 35 36 |
# File 'lib/fitting/response.rb', line 32 def route index.map do |i| "#{@request.route} #{@status} #{i}" end end |
#strict_fully_validates ⇒ Object
24 25 26 |
# File 'lib/fitting/response.rb', line 24 def strict_fully_validates @strict_fully_validates ||= Fitting::Response::FullyValidates.craft(@schemas, @body, true) end |
#strict_route ⇒ Object
38 39 40 41 42 |
# File 'lib/fitting/response.rb', line 38 def strict_route strict_index.map do |i| "#{@request.route} #{@status} #{i}" end end |
#within_prefix?(prefix) ⇒ Boolean
16 17 18 |
# File 'lib/fitting/response.rb', line 16 def within_prefix?(prefix) @request.within_prefix?(prefix) end |