Class: Openapi3Parser::CautiousDig

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(*args) ⇒ Object


7
8
9
# File 'lib/openapi3_parser/cautious_dig.rb', line 7

def self.call(*args)
  new.call(*args)
end

Instance Method Details

#call(collection, *segments) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/openapi3_parser/cautious_dig.rb', line 11

def call(collection, *segments)
  segments.inject(collection) do |next_depth, segment|
    break unless next_depth

    if next_depth.respond_to?(:keys)
      hash_like(next_depth, segment)
    elsif next_depth.respond_to?(:[])
      array_like(next_depth, segment)
    end
  end
end