Class: Rasti::Web::ApiDoc::Tracker

Inherits:
Object
  • Object
show all
Defined in:
lib/rasti/web/api_doc/tracker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(routes_by_method) ⇒ Tracker

Returns a new instance of Tracker.



8
9
10
11
12
13
14
15
# File 'lib/rasti/web/api_doc/tracker.rb', line 8

def initialize(routes_by_method)
  @tracks = Hash.new { |h,k| h[k] = {} }
  routes_by_method.each do |method, routes| 
    routes.each do |route| 
      tracks[method][route] = nil
    end
  end
end

Instance Attribute Details

#tracksObject (readonly)

Returns the value of attribute tracks.



6
7
8
# File 'lib/rasti/web/api_doc/tracker.rb', line 6

def tracks
  @tracks
end

Instance Method Details

#summaryObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rasti/web/api_doc/tracker.rb', line 27

def summary
  endpoints = tracks.values.flat_map(&:keys).count
  documented = tracks.values.flat_map(&:values).compact.count
  pending = Hash[tracks.map { |method, routes| [method, routes.select { |route, info| info.nil? }.keys ] }].select { |method, routes| !routes.empty? }

  {
    endpoints: endpoints,
    documented: documented,
    pending: pending.values.map(&:count).sum,
    pending_list: pending
  }
end

#track(env, response) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/rasti/web/api_doc/tracker.rb', line 17

def track(env, response)
  req = Rasti::Web::ApiDoc::Request.new(env)
  res = Rasti::Web::ApiDoc::Response.new(*response)

  if !tracks[req.method][req.route]
    STDOUT.puts "  #{Colorin.green_500(req.method.ljust(6, ' ')).bold} #{req.route}"
    tracks[req.method][req.route] = [req, res]
  end
end