Sha256: c7a99f295b4c0913a0dbc5c92c5ebc6f2c3525a2d7ab18977b2d72882b57463e

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

module Esplanade
  class Request
    class Doc
      def initialize(main_documentation, raw)
        @main_documentation = main_documentation
        @raw = raw
      end

      def tomogram
        raise PrefixNotMatch, message unless @main_documentation.prefix_match?(@raw.path)
        @tomogram = @main_documentation.find_request_with_content_type(
          method: @raw.method,
          path: @raw.path,
          content_type: @raw.content_type
        )
        raise NotDocumented, message if @tomogram.nil?
        @tomogram
      end

      def json_schema
        @json_schema ||= tomogram.request
      end

      def method
        @method ||= tomogram.method
      end

      def path
        @path ||= tomogram.path.to_s
      end

      def content_type
        @content_type ||= tomogram.content_type.to_s
      end

      def responses
        @responses ||= tomogram.responses
      rescue NotDocumented
        []
      end

      private

      def message
        {
          method: @raw.method,
          path: @raw.path,
          content_type: @raw.content_type
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
esplanade-1.3.0 lib/esplanade/request/doc.rb