Module: OpenAPIParser::Findable

Included in:
Schemas::Base
Defined in:
lib/openapi_parser/concerns/findable.rb

Instance Method Summary collapse

Instance Method Details

#find_object(reference) ⇒ OpenAPIParser::Findable

Parameters:

  • reference (String)

Returns:



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/openapi_parser/concerns/findable.rb', line 7

def find_object(reference)
  reference = CGI.unescape(reference)
  return self if object_reference == reference
  remote_reference = !reference.start_with?('#')
  return find_remote_object(reference) if remote_reference
  return nil unless reference.start_with?(object_reference)

  @find_object_cache = {} unless defined? @find_object_cache
  if (obj = @find_object_cache[reference])
    return obj
  end

  if (child = _openapi_all_child_objects[reference])
    @find_object_cache[reference] = child
    return child
  end

  _openapi_all_child_objects.values.each do |c|
    if (obj = c.find_object(reference))
      @find_object_cache[reference] = obj
      return obj
    end
  end

  nil
end

#purge_object_cacheObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/openapi_parser/concerns/findable.rb', line 34

def purge_object_cache
  @purged = false unless defined? @purged

  return if @purged

  @find_object_cache = {}
  @purged = true

  _openapi_all_child_objects.values.each(&:purge_object_cache)
end