Class: FunWithJsonApi::SchemaValidators::CheckCollectionIsAuthorised
- Inherits:
-
Object
- Object
- FunWithJsonApi::SchemaValidators::CheckCollectionIsAuthorised
- Defined in:
- lib/fun_with_json_api/schema_validators/check_collection_is_authorized.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#collection_ids ⇒ Object
readonly
Returns the value of attribute collection_ids.
-
#deserializer ⇒ Object
readonly
Returns the value of attribute deserializer.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(collection, collection_ids, deserializer, prefix: '/data') ⇒ CheckCollectionIsAuthorised
constructor
A new instance of CheckCollectionIsAuthorised.
- #resource_type ⇒ Object
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
#collection ⇒ Object (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_ids ⇒ Object (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 |
#deserializer ⇒ Object (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 |
#prefix ⇒ Object (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 ⇒ Object
6 7 8 |
# File 'lib/fun_with_json_api/schema_validators/check_collection_is_authorized.rb', line 6 def self.call(...) new(...).call end |
Instance Method Details
#call ⇒ Object
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| (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_type ⇒ Object
38 39 40 |
# File 'lib/fun_with_json_api/schema_validators/check_collection_is_authorized.rb', line 38 def resource_type deserializer.type end |