Sha256: abf69024a7d420d26f4cf1ece726eda47bec7d297e59724c80a3c02ce9e121f2

Contents?: true

Size: 1023 Bytes

Versions: 23

Compression:

Stored size: 1023 Bytes

Contents

module OasParser
  class Path
    attr_accessor :owner, :path, :raw

    def initialize(owner, path, raw)
      @owner = owner
      @path = path
      @raw = raw
    end

    def endpoints
      a = raw.map do |method, definition|
        next unless %w[get head post put patch delete trace options].include? method
        OasParser::Endpoint.new(self, method, definition)
      end

      a.compact
    end

    def endpoint_by_method(method)
      definition = raw[method]
      raise StandardError.new('So such endpoint exists') unless definition
      OasParser::Endpoint.new(self, method, definition)
    end

    def parameter_keys
      path.scan(/{(.+?)}/).flatten
    end

    def parameters
      return [] unless raw['parameters']
      raw['parameters'].map do |definition|
        OasParser::Parameter.new(self, definition)
      end
    end

    def definition
      owner if owner.class == OasParser::Definition
    end

    def callback
      owner if owner.class == OasParser::Callback
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
oas_parser-0.16.0 lib/oas_parser/path.rb
oas_parser-0.15.2 lib/oas_parser/path.rb
oas_parser-0.15.1 lib/oas_parser/path.rb
oas_parser-0.15.0 lib/oas_parser/path.rb
oas_parser-0.14.0 lib/oas_parser/path.rb
oas_parser-0.13.1 lib/oas_parser/path.rb
oas_parser-0.12.0 lib/oas_parser/path.rb
oas_parser-0.11.2 lib/oas_parser/path.rb
oas_parser-0.11.1 lib/oas_parser/path.rb
oas_parser-0.11.0 lib/oas_parser/path.rb
oas_parser-0.10.0 lib/oas_parser/path.rb
oas_parser-0.9.0 lib/oas_parser/path.rb
oas_parser-0.8.1 lib/oas_parser/path.rb
oas_parser-0.8.0 lib/oas_parser/path.rb
oas_parser-0.7.0 lib/oas_parser/path.rb
oas_parser-0.6.0 lib/oas_parser/path.rb
oas_parser-0.5.0 lib/oas_parser/path.rb
oas_parser-0.4.0 lib/oas_parser/path.rb
oas_parser-0.3.0 lib/oas_parser/path.rb
oas_parser-0.2.0 lib/oas_parser/path.rb