Sha256: a1639396772e314ef1fb5b9ed4dbcf587a46b83c0af90ce56af097e8d3b9cdc8

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

module Rasti
  module Web
    module ApiDoc
      class Tracker

        attr_reader :tracks        

        def initialize(routes)
          @tracks = Hash.new { |h,k| h[k] = {} }
          routes.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 "  #{req.method} #{req.route}".green
            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.count,
            pending_list: pending
          }
        end

      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rasti-web-api_doc-1.0.1 lib/rasti/web/api_doc/tracker.rb
rasti-web-api_doc-1.0.0 lib/rasti/web/api_doc/tracker.rb
rasti-web-api_doc-0.1.2 lib/rasti/web/api_doc/tracker.rb
rasti-web-api_doc-0.1.1 lib/rasti/web/api_doc/tracker.rb
rasti-web-api_doc-0.1.0 lib/rasti/web/api_doc/tracker.rb