Sha256: 4758a2d02eb011784c8647541628f0bbbe245936bb7fc1853e868299efe4690b

Contents?: true

Size: 881 Bytes

Versions: 3

Compression:

Stored size: 881 Bytes

Contents

module Esplanade
  class Response
    class Doc
      def initialize(request, raw)
        @request = request
        @raw = raw
      end

      def tomogram
        @tomogram ||= @request.doc.responses.find_all { |response| response['status'] == @raw.status }
        raise NotDocumented.new(**message) if @tomogram == []

        @tomogram
      rescue Esplanade::Request::PrefixNotMatch
        raise PrefixNotMatch.new(**message)
      end

      def json_schemas
        @json_schemas ||= tomogram.map { |action| action['body'] }
      end

      def status
        @status ||= tomogram['status']
      end

      private

      def message
        {
          request: {
            method: @request.raw.method,
            raw_path: @request.raw.raw_path,
            path: @request.raw.path
          },
          status: @raw.status
        }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
esplanade-1.7.1 lib/esplanade/response/doc.rb
esplanade-1.7.0 lib/esplanade/response/doc.rb
esplanade-1.6.0 lib/esplanade/response/doc.rb