Class: Wings::ModelTransformer
- Inherits:
-
Object
- Object
- Wings::ModelTransformer
- Defined in:
- lib/wings/model_transformer.rb
Overview
Transforms ActiveFedora models or objects into Valkyrie::Resource models or objects
Similar to an orm_converter class in other valkyrie persisters. Also used by the Valkyrizable mixin to make AF objects able to return their Valkyrie::Resource representation.
Defined Under Namespace
Classes: ResourceClassCache
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#build ⇒ ::Valkyrie::Resource
Builds a ‘Valkyrie::Resource` equivalent to the `pcdm_object`.
- #cache ⇒ ResourceClassCache
- #ensure_current_permissions(resource) ⇒ Object
-
#initialize(pcdm_object:) ⇒ ModelTransformer
constructor
A new instance of ModelTransformer.
Constructor Details
#initialize(pcdm_object:) ⇒ ModelTransformer
Returns a new instance of ModelTransformer.
28 29 30 |
# File 'lib/wings/model_transformer.rb', line 28 def initialize(pcdm_object:) self.pcdm_object = pcdm_object end |
Instance Attribute Details
#pcdm_object ⇒ ActiveFedora::Base
24 25 26 |
# File 'lib/wings/model_transformer.rb', line 24 def pcdm_object @pcdm_object end |
Class Method Details
.for(pcdm_object) ⇒ ::Valkyrie::Resource
Factory
38 39 40 |
# File 'lib/wings/model_transformer.rb', line 38 def self.for(pcdm_object) new(pcdm_object: pcdm_object).build end |
Instance Method Details
#build ⇒ ::Valkyrie::Resource
Builds a ‘Valkyrie::Resource` equivalent to the `pcdm_object`
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/wings/model_transformer.rb', line 46 def build klass = cache.fetch(pcdm_object.class) do OrmConverter.to_valkyrie_resource_class(klass: pcdm_object.class) end mint_id unless pcdm_object.id attrs = attributes.tap { |hash| hash[:new_record] = pcdm_object.new_record? } attrs[:alternate_ids] = [::Valkyrie::ID.new(pcdm_object.id)] if pcdm_object.id klass.new(**attrs).tap { |resource| (resource) } end |
#cache ⇒ ResourceClassCache
72 73 74 |
# File 'lib/wings/model_transformer.rb', line 72 def cache ResourceClassCache.instance end |
#ensure_current_permissions(resource) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/wings/model_transformer.rb', line 59 def (resource) return if pcdm_object.try(:access_control).blank? # set permissions on the locally cached permission manager if one is present, # otherwise, we can just rely on the `access_control_ids`. return unless resource.respond_to?(:permission_manager) resource..acl. = pcdm_object.access_control.valkyrie_resource. end |