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


14
15
16
17
# File 'lib/oas_parser/definition.rb', line 14

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


5
6
7
# File 'lib/oas_parser/definition.rb', line 5

def path
  @path
end

#rawObject

Returns the value of attribute raw


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

def raw
  @raw
end

Class Method Details

.resolve(path) ⇒ Object


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

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

Instance Method Details

#endpointsObject


39
40
41
# File 'lib/oas_parser/definition.rb', line 39

def endpoints
  paths.flat_map(&:endpoints)
end

#formatObject


19
20
21
# File 'lib/oas_parser/definition.rb', line 19

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

#path_by_path(path) ⇒ Object

Raises:

  • (StandardError)

29
30
31
32
33
# File 'lib/oas_parser/definition.rb', line 29

def path_by_path(path)
  definition = raw['paths'][path]
  raise StandardError.new('So such path exists') unless definition
  OasParser::Path.new(self, path, definition)
end

#pathsObject


23
24
25
26
27
# File 'lib/oas_parser/definition.rb', line 23

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

#securityObject


35
36
37
# File 'lib/oas_parser/definition.rb', line 35

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