Class: FunWithJsonApi::SchemaValidators::CheckCollectionHasAllMembers

Inherits:
Object
  • Object
show all
Defined in:
lib/fun_with_json_api/schema_validators/check_collection_has_all_members.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, document_ids, deserializer, prefix: '/data') ⇒ CheckCollectionHasAllMembers

Returns a new instance of CheckCollectionHasAllMembers.



17
18
19
20
21
22
# File 'lib/fun_with_json_api/schema_validators/check_collection_has_all_members.rb', line 17

def initialize(collection, document_ids, deserializer, prefix: '/data')
  @collection = collection
  @document_ids = document_ids
  @deserializer = deserializer
  @prefix = prefix
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



10
11
12
# File 'lib/fun_with_json_api/schema_validators/check_collection_has_all_members.rb', line 10

def collection
  @collection
end

#deserializerObject (readonly)

Returns the value of attribute deserializer.



12
13
14
# File 'lib/fun_with_json_api/schema_validators/check_collection_has_all_members.rb', line 12

def deserializer
  @deserializer
end

#document_idsObject (readonly)

Returns the value of attribute document_ids.



11
12
13
# File 'lib/fun_with_json_api/schema_validators/check_collection_has_all_members.rb', line 11

def document_ids
  @document_ids
end

#prefixObject (readonly)

Returns the value of attribute prefix.



13
14
15
# File 'lib/fun_with_json_api/schema_validators/check_collection_has_all_members.rb', line 13

def prefix
  @prefix
end

Class Method Details

.callObject



6
7
8
# File 'lib/fun_with_json_api/schema_validators/check_collection_has_all_members.rb', line 6

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

Instance Method Details

#callObject



24
25
26
27
28
29
# File 'lib/fun_with_json_api/schema_validators/check_collection_has_all_members.rb', line 24

def call
  if collection.size != document_ids.size
    collection_ids = deserializer.format_collection_ids(collection)
    raise build_missing_resources_error(collection_ids)
  end
end

#resource_typeObject



31
32
33
# File 'lib/fun_with_json_api/schema_validators/check_collection_has_all_members.rb', line 31

def resource_type
  deserializer.type
end