Sha256: b256636ea047c5f3b86dd72baa47ca9e9be3215aeab8afefe968f6e1a4b27d02

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

module Rasti
  module Web
    module ApiDoc
      class Tracker

        attr_reader :tracks        

        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

        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

        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

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rasti-web-api_doc-1.1.0 lib/rasti/web/api_doc/tracker.rb