Class: Hyrax::ValkyrieGlobalIdProxy

Inherits:
Object
  • Object
show all
Defined in:
app/models/hyrax/valkyrie_global_id_proxy.rb

Overview

Support GlobalID and ActiveJob Serialization/Deserialization for `Valkyrie::Resource` models.

Examples:

Serializing a Valkyrie::Resource for ActiveJob

resource = Hyrax.query_service.find_by(id: Valkyrie::ID.new('an_id'))

MyJob.perform_later(resource) # #<ActiveJob::SerializationError: Unsupported argument type: >

proxy = Hyrax::ValkyrieGlobalIdProxy.new(resource: resource)
MyJob.perform_later(proxy) # deserializes for `MyJob#perform` as `resource`

See Also:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource:) ⇒ ValkyrieGlobalIdProxy

Returns a new instance of ValkyrieGlobalIdProxy.

Parameters:


28
29
30
# File 'app/models/hyrax/valkyrie_global_id_proxy.rb', line 28

def initialize(resource:)
  self.resource = resource
end

Instance Attribute Details

#resourceHyrax::Resource

Returns:


24
25
26
# File 'app/models/hyrax/valkyrie_global_id_proxy.rb', line 24

def resource
  @resource
end

Class Method Details

.find(id) ⇒ Valkyrie::Resource

Returns:

  • (Valkyrie::Resource)

34
35
36
# File 'app/models/hyrax/valkyrie_global_id_proxy.rb', line 34

def self.find(id)
  Hyrax.query_service.find_by(id: id)
end

Instance Method Details

#idString

Returns:

  • (String)

40
41
42
# File 'app/models/hyrax/valkyrie_global_id_proxy.rb', line 40

def id
  resource.id.to_s
end