Class: Wings::Valkyrie::ResourceFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/wings/valkyrie/resource_factory.rb

Overview

This class provides two-way mapping between ‘ActiveFedora::Base` and `Valkyrie::Resource` models.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter:) ⇒ ResourceFactory

Returns a new instance of ResourceFactory.

Parameters:



23
24
25
# File 'lib/wings/valkyrie/resource_factory.rb', line 23

def initialize(adapter:)
  @adapter = adapter
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



17
18
19
# File 'lib/wings/valkyrie/resource_factory.rb', line 17

def adapter
  @adapter
end

Instance Method Details

#from_resource(resource:) ⇒ ActiveFedora::Base

Returns ActiveFedora resource for the Valkyrie resource.

Parameters:

  • resource (Valkyrie::Resource)

    Model to be converted to ActiveRecord.

Returns:



40
41
42
# File 'lib/wings/valkyrie/resource_factory.rb', line 40

def from_resource(resource:)
  ActiveFedoraConverter.new(resource: resource).convert
end

#to_resource(object:) ⇒ Valkyrie::Resource

Returns Model representation of the AF record.

Parameters:

Returns:

  • (Valkyrie::Resource)

    Model representation of the AF record.



31
32
33
# File 'lib/wings/valkyrie/resource_factory.rb', line 31

def to_resource(object:)
  object.valkyrie_resource
end