Sha256: a23172ac00e18da5dbdaf1e3855918ca4f4b9838cadbc6623c9877c6d6ac4776

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

# -*- encoding : utf-8 -*-
module Pacto
  module Observers
    class Stenographer
      def initialize(output)
        @output = output
      end

      def log_investigation(investigation)
        return if @output.nil?

        contract = investigation.contract
        request = investigation.request
        response = investigation.response
        name = name_for(contract, request)
        values = values_for(contract, request)

        msg = "request #{name.inspect}, values: #{values.inspect}, response: {status: #{response.status}} # #{number_of_citations(investigation)} contract violations"
        @output.puts msg
        @output.flush
      end

      protected

      def name_for(contract, request)
        return "Unknown (#{request.uri})" if contract.nil?
        contract.name
      end

      def number_of_citations(investigation)
        return 0 if investigation.nil?
        return 0 if investigation.citations.nil?
        investigation.citations.size.to_s
      end

      def values_for(_contract, request)
        # FIXME: Extract vars w/ URI::Template
        request.uri.query_values
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pacto-0.4.0.rc3 lib/pacto/observers/stenographer.rb
pacto-0.4.0.rc2 lib/pacto/observers/stenographer.rb
pacto-0.4.0.rc1 lib/pacto/observers/stenographer.rb