Module: Servus::Schema::Path Private

Defined in:
lib/servus/schema/path.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Walks a path of literal keys into a registered schema fragment.

This is the single addressing implementation behind both fetch and $ref resolution, so a path that misses reads the same whether application code asked for it directly or a ref led there.

Segments are literal hash keys, not JSON Pointer tokens — there is no +~0+/+~1+ unescaping and no array indexing.

See Also:

Class Method Summary collapse

Class Method Details

.walk(fragment, key, path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Walks path into fragment.

Parameters:

  • fragment (Hash)

    the registered fragment

  • key (String)

    the fragment key, for the error message

  • path (Array<String>)

    segments to walk

Returns:

  • (Object)

    the value at the path, or the fragment if path is empty

Raises:



26
27
28
29
30
31
32
33
34
# File 'lib/servus/schema/path.rb', line 26

def walk(fragment, key, path)
  path.reduce(fragment) do |current, segment|
    unless current.is_a?(Hash) && current.key?(segment)
      raise RefNotFoundError, message_for(key, path, segment, current)
    end

    current[segment]
  end
end