Sha256: d41b71d7b3ad642e1c544fbba58949834a3eb2f3c9c7cbe0ff768539067f7ac1
Contents?: true
Size: 1.12 KB
Versions: 4
Compression:
Stored size: 1.12 KB
Contents
# frozen_string_literal: true require "openapi3_parser/error" module Openapi3Parser class Document class ReferenceRegister attr_reader :sources, :factories def initialize @sources = [] @factories = [] end def register(factory) error = "Can't register references when the register is frozen" raise Error::ImmutableObject, error if frozen? context = factory.context add_source(context.source_location.source) add_factory(factory) end def freeze sources.freeze factories.freeze super end private def add_source(source) return if sources.include?(source) sources << source end def add_factory(factory) return if factory_registered?(factory) factories << factory end def factory_registered?(factory) source_location = factory.context.source_location factories.any? do |f| same_location = f.context.source_location == source_location same_location && f.class == factory.class end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems