Class: FunWithJsonApi::SchemaValidators::CheckCollectionIsAuthorised

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, collection_ids, deserializer, prefix: '/data') ⇒ CheckCollectionIsAuthorised

Returns a new instance of CheckCollectionIsAuthorised.



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

def initialize(collection, collection_ids, deserializer, prefix: '/data')
  @collection = collection
  @collection_ids = collection_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_is_authorized.rb', line 10

def collection
  @collection
end

#collection_idsObject (readonly)

Returns the value of attribute collection_ids.



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

def collection_ids
  @collection_ids
end

#deserializerObject (readonly)

Returns the value of attribute deserializer.



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

def deserializer
  @deserializer
end

#prefixObject (readonly)

Returns the value of attribute prefix.



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

def prefix
  @prefix
end

Class Method Details

.call(*args) ⇒ Object



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

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

Instance Method Details

#callObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fun_with_json_api/schema_validators/check_collection_is_authorized.rb', line 25

def call
  payload = collection.each_with_index.map do |resource, index|
    build_unauthorized_resource_payload(resource, index)
  end.reject(&:nil?)

  return if payload.empty?

  raise Exceptions::UnauthorizedResource.new(
    "resource_authorizer method for one or more '#{deserializer.type}' items returned false",
    payload
  )
end

#resource_typeObject



38
39
40
# File 'lib/fun_with_json_api/schema_validators/check_collection_is_authorized.rb', line 38

def resource_type
  deserializer.type
end