Class: Fitting::NoCov
- Inherits:
-
Object
- Object
- Fitting::NoCov
- Defined in:
- lib/fitting/nocov.rb
Defined Under Namespace
Classes: NotFound
Class Method Summary collapse
Instance Method Summary collapse
- #find(docs) ⇒ Object
-
#initialize(host, method, path, code, content_type, combination, combination_next) ⇒ NoCov
constructor
A new instance of NoCov.
Constructor Details
#initialize(host, method, path, code, content_type, combination, combination_next) ⇒ NoCov
Returns a new instance of NoCov.
5 6 7 8 9 10 11 12 13 |
# File 'lib/fitting/nocov.rb', line 5 def initialize(host, method, path, code, content_type, combination, combination_next) @host = host @method = method @path = path @code = code @content_type = content_type @combination = combination @combination_next = combination_next end |
Class Method Details
.all(yaml) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/fitting/nocov.rb', line 15 def self.all(yaml) return [] unless yaml['NoCov'] yaml['NoCov'].map do |action| new(action['host'], action['method'], action['path'], action['code'], action['content-type'], action['combination'], action['combination_next']) end end |
Instance Method Details
#find(docs) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fitting/nocov.rb', line 22 def find(docs) res = docs.find do |action| action.host == @host && action.method == @method && action.path_match(@path) end if @code == nil return res if res.present? raise NotFound.new("host: #{@host}, method: #{@method}, path: #{@path}") end if res == nil raise NotFound.new("host: #{@host}, method: #{@method}, path: #{@path}") end res_code = res.responses.find { |response| response.step_key == @code.to_s } if @content_type == nil return res_code if res_code.present? raise NotFound.new("host: #{@host}, method: #{@method}, path: #{@path}, code: #{@code}") end res_content_type = res_code.next_steps.find { |content_type| content_type.step_key == @content_type.to_s } if @combination == nil return res_content_type if res_content_type.present? raise NotFound.new("host: #{@host}, method: #{@method}, path: #{@path}, code: #{@code}, content-type: #{@content_type}") end res_json_schema = res_content_type.next_steps[0] res_combination = res_json_schema.next_steps.find do |combination| combination.step_key == @combination.to_s end if @combination_next == nil return res_combination if res_combination raise NotFound.new("host: #{@host}, method: #{@method}, path: #{@path}, code: #{@code}, content-type: #{@content_type}, combination: #{@combination}") end res_combination_next = res_combination.next_steps.find do |combination_next| combination_next.step_key == @combination_next.to_s end return res_combination_next if res_combination_next raise NotFound.new("host: #{@host}, method: #{@method}, path: #{@path}, code: #{@code}, content-type: #{@content_type}, combination: #{@combination}, combination_next: #{@combination_next}") end |