Class: OasParser::Definition

Inherits:
Object
  • Object
show all
Includes:
RawAccessor
Defined in:
lib/oas_parser/definition.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RawAccessor

included, #method_missing, #respond_to_missing?

Constructor Details

#initialize(raw, path) ⇒ Definition

Returns a new instance of Definition.



16
17
18
19
# File 'lib/oas_parser/definition.rb', line 16

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class OasParser::RawAccessor

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/oas_parser/definition.rb', line 7

def path
  @path
end

#rawObject

Returns the value of attribute raw.



9
10
11
# File 'lib/oas_parser/definition.rb', line 9

def raw
  @raw
end

Class Method Details

.resolve(path) ⇒ Object



11
12
13
14
# File 'lib/oas_parser/definition.rb', line 11

def self.resolve(path)
  raw = Parser.resolve(path)
  Definition.new(raw, path)
end

Instance Method Details

#endpointsObject



47
48
49
# File 'lib/oas_parser/definition.rb', line 47

def endpoints
  paths.flat_map(&:endpoints)
end

#formatObject



21
22
23
# File 'lib/oas_parser/definition.rb', line 21

def format
  File.extname(@path).sub('.', '')
end

#path_by_path(path) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/oas_parser/definition.rb', line 31

def path_by_path(path)
  definition = raw['paths'][path]
  return OasParser::Path.new(self, path, definition) if definition

  key = raw['paths'].keys.detect do |path_entry|
    Mustermann::Template.new(path_entry).match(path)
  end
  definition = raw['paths'][key]
  raise OasParser::PathNotFound.new("Path not found: '#{path}'") unless definition
  OasParser::Path.new(self, key, definition)
end

#pathsObject



25
26
27
28
29
# File 'lib/oas_parser/definition.rb', line 25

def paths
  raw['paths'].map do |path, definition|
    OasParser::Path.new(self, path, definition)
  end
end

#securityObject



43
44
45
# File 'lib/oas_parser/definition.rb', line 43

def security
  raw['security'] || []
end