Class: RSpec::JsonMatchers::Utils::KeyPath::Extraction Private
- Inherits:
-
Object
- Object
- RSpec::JsonMatchers::Utils::KeyPath::Extraction
- 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.
Represents an extractor that performs the extraction with a #path & #object
Defined Under Namespace
Classes: ExtractionWithOnePathPart, Result
Instance Method Summary collapse
-
#extract ⇒ Extraction::Result
private
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.
-
#initialize(object, path) ⇒ Extraction
constructor
private
Create a new extractor with the “source object” and the path to be used for extracting our target object.
Constructor Details
#initialize(object, path) ⇒ Extraction
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
21 22 23 24 25 26 |
# File 'lib/rspec/json_matchers/utils/key_path/extraction.rb', line 21 def initialize(object, path) @object = object @path = KeyPath::Path.new(path) @failed = false end |
Instance Method Details
#extract ⇒ Extraction::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
Assume the path to be valid
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rspec/json_matchers/utils/key_path/extraction.rb', line 35 def extract path.each_path_part do |path_part| result = extract_object_with_path_part(path_part) return Result.new(object, false) if result.failed? self.object = result.object end Result.new(object, true) end |