Class: OasParser::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/oas_parser_reborn/path.rb

Direct Known Subclasses

Webhook

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, path, raw) ⇒ Path

Returns a new instance of Path.



5
6
7
8
9
# File 'lib/oas_parser_reborn/path.rb', line 5

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

Instance Attribute Details

#ownerObject

Returns the value of attribute owner.



3
4
5
# File 'lib/oas_parser_reborn/path.rb', line 3

def owner
  @owner
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/oas_parser_reborn/path.rb', line 3

def path
  @path
end

#rawObject

Returns the value of attribute raw.



3
4
5
# File 'lib/oas_parser_reborn/path.rb', line 3

def raw
  @raw
end

Instance Method Details

#callbackObject



41
42
43
# File 'lib/oas_parser_reborn/path.rb', line 41

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

#definitionObject



37
38
39
# File 'lib/oas_parser_reborn/path.rb', line 37

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

#endpoint_by_method(method) ⇒ Object



20
21
22
23
24
# File 'lib/oas_parser_reborn/path.rb', line 20

def endpoint_by_method(method)
  definition = raw[method]
  raise OasParser::MethodNotFound.new("HTTP method not found: '#{method}'") unless definition
  OasParser::Endpoint.new(self, method, definition)
end

#endpointsObject



11
12
13
14
15
16
17
18
# File 'lib/oas_parser_reborn/path.rb', line 11

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

#parameter_keysObject



26
27
28
# File 'lib/oas_parser_reborn/path.rb', line 26

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

#parametersObject



30
31
32
33
34
35
# File 'lib/oas_parser_reborn/path.rb', line 30

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