Class: Openapi3Parser::Document::ReferenceRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi3_parser/document/reference_registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReferenceRegistry

Returns a new instance of ReferenceRegistry.



8
9
10
11
# File 'lib/openapi3_parser/document/reference_registry.rb', line 8

def initialize
  @sources = []
  @factories_by_type = {}
end

Instance Attribute Details

#sourcesObject (readonly)

Returns the value of attribute sources.



6
7
8
# File 'lib/openapi3_parser/document/reference_registry.rb', line 6

def sources
  @sources
end

Instance Method Details

#factoriesObject



19
20
21
# File 'lib/openapi3_parser/document/reference_registry.rb', line 19

def factories
  factories_by_type.values.flatten
end

#factory(object_type, source_location) ⇒ Object



37
38
39
40
41
# File 'lib/openapi3_parser/document/reference_registry.rb', line 37

def factory(object_type, source_location)
  factories_by_type[object_type]&.find do |f|
    f.context.source_location == source_location
  end
end

#freezeObject



13
14
15
16
17
# File 'lib/openapi3_parser/document/reference_registry.rb', line 13

def freeze
  sources.freeze
  factories_by_type.freeze.each(&:freeze)
  super
end

#register(unbuilt_factory, source_location, reference_factory_context) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/openapi3_parser/document/reference_registry.rb', line 23

def register(unbuilt_factory, source_location, reference_factory_context)
  register_source(source_location.source)
  object_type = unbuilt_factory.object_type
  existing_factory = factory(object_type, source_location)

  return existing_factory if existing_factory

  build_factory(
    unbuilt_factory,
    source_location,
    reference_factory_context
  ).tap { |f| register_factory(object_type, f) }
end