Class: Hyrax::ValkyrieCanCanAdapter

Inherits:
CanCan::ModelAdapters::AbstractAdapter
  • Object
show all
Defined in:
lib/hyrax/valkyrie_can_can_adapter.rb

Overview

A `CanCan::ModelAdapter` for valkyrie resources

Class Method Summary collapse

Class Method Details

.find(_model_class, id) ⇒ Hyrax::Resource

Parameters:

  • model_class (Class)
  • id (String)

Returns:

Raises:

  • Hyrax::ObjectNotFoundError


21
22
23
24
25
26
# File 'lib/hyrax/valkyrie_can_can_adapter.rb', line 21

def self.find(_model_class, id)
  return Hyrax.query_service.find_by(id: id) unless Hyrax.config.enable_noids?
  Hyrax.query_service.find_by_alternate_identifier(alternate_identifier: id)
rescue Valkyrie::Persistence::ObjectNotFoundError => err
  raise Hyrax::ObjectNotFoundError, err.message
end

.for_class?(member_class) ⇒ Boolean

Parameters:

  • member_class (Class)

Returns:

  • (Boolean)

9
10
11
12
# File 'lib/hyrax/valkyrie_can_can_adapter.rb', line 9

def self.for_class?(member_class)
  member_class == Hyrax::Resource ||
    member_class < Hyrax::Resource
end