Sha256: 2522bbb01fbb82e457102932291d6cbeeda9d5f62a4caada78171551b9861c8b

Contents?: true

Size: 1.15 KB

Versions: 6

Compression:

Stored size: 1.15 KB

Contents

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

      def tomogram
        raise PrefixNotMatch.new(**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.new(**message) if @tomogram.nil?

        @tomogram
      end

      def json_schemas
        @json_schemas ||= tomogram.requests
      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,
          raw_path: @raw.raw_path,
          content_type: @raw.content_type
        }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
esplanade-1.8.2 lib/esplanade/request/doc.rb
esplanade-1.8.1 lib/esplanade/request/doc.rb
esplanade-1.8.0 lib/esplanade/request/doc.rb
esplanade-1.7.1 lib/esplanade/request/doc.rb
esplanade-1.7.0 lib/esplanade/request/doc.rb
esplanade-1.6.0 lib/esplanade/request/doc.rb