Class: Fitting::Doc

Inherits:
Object
  • Object
show all
Defined in:
lib/fitting/doc.rb,
lib/fitting/doc/code.rb,
lib/fitting/doc/step.rb,
lib/fitting/doc/action.rb,
lib/fitting/doc/json_schema.rb,
lib/fitting/doc/content_type.rb,
lib/fitting/doc/combination_enum.rb,
lib/fitting/doc/combination_step.rb,
lib/fitting/doc/combination_one_of.rb,
lib/fitting/doc/combination_optional.rb

Defined Under Namespace

Classes: Action, Code, CombinationEnum, CombinationOneOf, CombinationOptional, CombinationStep, ContentType, JsonSchema, NotFound, Step

Class Method Summary collapse

Class Method Details

.allObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
# File 'lib/fitting/doc.rb', line 8

def self.all
  apis = YAML.safe_load(File.read('.fitting.yml'))['APIs']
  return [] unless apis
  apis.map do |api|
    if api['type'] == 'openapi2'
      Tomograph::Tomogram.new(prefix: api['prefix'] || '', openapi2_json_path: api['path']).to_a.map do |action|
        Fitting::Doc::Action.new(
          api['host'],
          api['prefix'] || '',
          action.to_hash['method'],
          action.to_hash['path'].path,
          action.responses
        )
      end
    elsif api['type'] == 'openapi3'
      Tomograph::Tomogram.new(prefix: api['prefix'] || '', openapi3_yaml_path: api['path']).to_a.map do |action|
        Fitting::Doc::Action.new(
          api['host'],
          api['prefix'] || '',
          action.to_hash['method'],
          action.to_hash['path'].path,
          action.responses
        )
      end
    elsif api['type'] == 'drafter'
      Tomograph::Tomogram.new(prefix: api['prefix'] || '', drafter_yaml_path: api['path']).to_a.map do |action|
        Fitting::Doc::Action.new(
          api['host'],
          api['prefix'] || '',
          action.to_hash['method'],
          action.to_hash['path'].path,
          action.responses
        )
      end
    elsif api['type'] == 'crafter'
      Tomograph::Tomogram.new(prefix: api['prefix'] || '', crafter_yaml_path: api['path']).to_a.map do |action|
        Fitting::Doc::Action.new(
          api['host'],
          api['prefix'] || '',
          action.to_hash['method'],
          action.to_hash['path'].path,
          action.responses
        )
      end
    elsif api['type'] == 'tomogram'
      Tomograph::Tomogram.new(prefix: api['prefix'] || '', tomogram_json_path: api['path']).to_a.map do |action|
        Fitting::Doc::Action.new(
          api['host'],
          api['prefix'] || '',
          action.to_hash['method'],
          action.to_hash['path'].path,
          action.responses
        )
      end
    end
  end.flatten
end

.cover!(docs, log) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/fitting/doc.rb', line 66

def self.cover!(docs, log)
  docs.each do |doc|
    return if doc.cover!(log)
  end
  raise NotFound.new "log: #{log.method} #{log.host} #{log.url} #{log.status}"
rescue Fitting::Doc::Action::NotFound => e
  raise NotFound.new "log error: #{e.message}"
end

.debug(docs, debug) ⇒ Object

Raises:



75
76
77
78
79
80
81
# File 'lib/fitting/doc.rb', line 75

def self.debug(docs, debug)
  docs.each do |doc|
    res = doc.debug(debug)
    return res if res
  end
  raise NotFound
end

.report(actions) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/fitting/doc.rb', line 83

def self.report(actions)
  all = 0
  cov = 0
  actions.each do |action|
    action.to_hash.values.first.each do |cover_line|
      if cover_line == nil
        next
      elsif cover_line == 0
        all += 1
      elsif cover_line > 0
        all += 1
        cov += 1
      end
    end
  end
  res = (cov.to_f / all.to_f * 100).round(2)
  puts "Coverage: #{res}%"
  if res == 100.00
    exit 0
  else
    exit 1
  end
end