Class: RSpec::JsonMatchers::Utils::KeyPath::Extraction::ExtractionWithOnePathPart Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/json_matchers/utils/key_path/extraction.rb

Overview

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

Internal implementation for an extraction operation with only one part of the path

Instance Method Summary collapse

Constructor Details

#initialize(object, path_part) ⇒ ExtractionWithOnePathPart

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.

Create a new extractor with the “source object” and the path to be used for extracting our target object

Parameters:

  • object (Object)

    The source object to extract our target object from

  • path_part (String)

    a part of Path of target object



80
81
82
83
# File 'lib/rspec/json_matchers/utils/key_path/extraction.rb', line 80

def initialize(object, path_part)
  @object = object
  @path_part = path_part
end

Instance Method Details

#extractExtraction::Result

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.

Actually perform the extraction and return the result Since the object could be falsy, an object of custom class is returned instead of the object only

Returns:



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/rspec/json_matchers/utils/key_path/extraction.rb', line 90

def extract
  case object
  when Hash
    extract_object_from_hash
  when Array
    extract_object_from_array
  else
    # Disallow non JSON collection type
    Result.new(object, false)
  end
end