Class: Hyrax::CustomQueries::FindAccessControl

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/custom_queries/find_access_control.rb

Overview

Examples:

Hyrax.custom_queries.find_access_control_for(resource: resource)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query_service:) ⇒ FindAccessControl

Returns a new instance of FindAccessControl.



11
12
13
# File 'app/services/hyrax/custom_queries/find_access_control.rb', line 11

def initialize(query_service:)
  @query_service = query_service
end

Instance Attribute Details

#query_serviceObject (readonly)

Returns the value of attribute query_service.



15
16
17
# File 'app/services/hyrax/custom_queries/find_access_control.rb', line 15

def query_service
  @query_service
end

Class Method Details

.queriesObject



7
8
9
# File 'app/services/hyrax/custom_queries/find_access_control.rb', line 7

def self.queries
  [:find_access_control_for]
end

Instance Method Details

#find_access_control_for(resource:) ⇒ Object



18
19
20
21
22
23
24
25
# File 'app/services/hyrax/custom_queries/find_access_control.rb', line 18

def find_access_control_for(resource:)
  query_service
    .find_inverse_references_by(resource: resource, property: :access_to)
    .find { |r| r.is_a?(Hyrax::AccessControl) } ||
    raise(Valkyrie::Persistence::ObjectNotFoundError)
rescue ArgumentError # some adapters raise ArgumentError for missing resources
  raise(Valkyrie::Persistence::ObjectNotFoundError)
end