Class: OpenapiContracts::PayloadParser

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/openapi_contracts/payload_parser.rb

Defined Under Namespace

Classes: Entry

Instance Method Summary collapse

Constructor Details

#initializePayloadParser

Returns a new instance of PayloadParser.



21
22
23
# File 'lib/openapi_contracts/payload_parser.rb', line 21

def initialize
  @parsers = []
end

Instance Method Details

#parse(media_type, payload) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
30
# File 'lib/openapi_contracts/payload_parser.rb', line 25

def parse(media_type, payload)
  parser = @parsers.find { |e| e.match?(media_type) }
  raise ArgumentError, "#{media_type.inspect} is not supported yet" unless parser

  parser.call(payload)
end

#register(matcher, parser) ⇒ Object



32
33
34
# File 'lib/openapi_contracts/payload_parser.rb', line 32

def register(matcher, parser)
  @parsers << Entry.new(matcher, parser)
end