Class: Insights::API::Common::OpenApi::Docs::ComponentCollection

Inherits:
Hash
  • Object
show all
Defined in:
lib/insights/api/common/open_api/docs/component_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, category) ⇒ ComponentCollection

Returns a new instance of ComponentCollection.



9
10
11
12
# File 'lib/insights/api/common/open_api/docs/component_collection.rb', line 9

def initialize(doc, category)
  @doc = doc
  @category = category
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



7
8
9
# File 'lib/insights/api/common/open_api/docs/component_collection.rb', line 7

def doc
  @doc
end

Instance Method Details

#[](name) ⇒ Object



14
15
16
# File 'lib/insights/api/common/open_api/docs/component_collection.rb', line 14

def [](name)
  super || load_definition(name)
end

#load_definition(name) ⇒ Object

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
# File 'lib/insights/api/common/open_api/docs/component_collection.rb', line 18

def load_definition(name)
  raw_definition = @doc.content.fetch_path(*@category.split("/"), name)
  raise ArgumentError, "Failed to find definition for #{name}" unless raw_definition.kind_of?(Hash)

  definition = substitute_regexes(raw_definition)
  definition = substitute_references(definition)
  self[name] = ::Insights::API::Common::OpenApi::Docs::ObjectDefinition.new.replace(definition)
end