Class: RSpec::JsonMatchers::Utils::CollectionKeysExtractor Private

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

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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection) ⇒ CollectionKeysExtractor

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.

Returns a new instance of CollectionKeysExtractor.



23
24
25
# File 'lib/rspec/json_matchers/utils/collection_keys_extractor.rb', line 23

def initialize(collection)
  @collection = collection
end

Instance Attribute Details

#collectionObject (readonly)

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.



21
22
23
# File 'lib/rspec/json_matchers/utils/collection_keys_extractor.rb', line 21

def collection
  @collection
end

Class Method Details

.extract(collection) ⇒ Set

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.

Returns set of keys/indexes of the collection.

Parameters:

  • collection (Array, Hash)

Returns:

  • (Set)

    set of keys/indexes of the collection

Raises:

  • (TypeError)

    When collection is not one of expected types



11
12
13
# File 'lib/rspec/json_matchers/utils/collection_keys_extractor.rb', line 11

def self.extract(collection)
  new(collection).extract
end

Instance Method Details

#extractObject

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.



27
28
29
30
31
32
# File 'lib/rspec/json_matchers/utils/collection_keys_extractor.rb', line 27

def extract
  COLLECTION_TYPE_TO_VALUE_EXTRACTION_PROC_MAP.
    fetch(collection.class) do
      fail TypeError
    end.call(collection)
end