Sha256: d33170bfaee5b4fd3b6b438410e674e317da484c00d370b1f2a4c7a209e660ac

Contents?: true

Size: 1.13 KB

Versions: 28

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require 'wings/active_fedora_converter'

module Wings
  module Valkyrie
    ##
    # This class provides two-way mapping between `ActiveFedora::Base` and
    # `Valkyrie::Resource` models.
    #
    # @see Wings::ActiveFedoraConverter
    # @see Wings::Valkyrizable
    class ResourceFactory
      ##
      # @!attribute [r] adapter
      #   @return [MetadataAdapter]
      attr_reader :adapter

      delegate :id, to: :adapter, prefix: true

      ##
      # @param [MetadataAdapter] adapter
      def initialize(adapter:)
        @adapter = adapter
      end

      ##
      # @param object [ActiveFedora::Base] AF record to be converted.
      #
      # @return [Valkyrie::Resource] Model representation of the AF record.
      def to_resource(object:)
        object.valkyrie_resource
      end

      ##
      # @param resource [Valkyrie::Resource] Model to be converted to ActiveRecord.
      #
      # @return [ActiveFedora::Base] ActiveFedora
      #   resource for the Valkyrie resource.
      def from_resource(resource:)
        ActiveFedoraConverter.new(resource: resource).convert
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
hyrax-5.0.1 lib/wings/valkyrie/resource_factory.rb
hyrax-5.0.0 lib/wings/valkyrie/resource_factory.rb
hyrax-5.0.0.rc3 lib/wings/valkyrie/resource_factory.rb
hyrax-5.0.0.rc2 lib/wings/valkyrie/resource_factory.rb
hyrax-5.0.0.rc1 lib/wings/valkyrie/resource_factory.rb
hyrax-3.6.0 lib/wings/valkyrie/resource_factory.rb
hyrax-4.0.0 lib/wings/valkyrie/resource_factory.rb
hyrax-4.0.0.rc3 lib/wings/valkyrie/resource_factory.rb
hyrax-4.0.0.rc2 lib/wings/valkyrie/resource_factory.rb
hyrax-4.0.0.rc1 lib/wings/valkyrie/resource_factory.rb
hyrax-3.5.0 lib/wings/valkyrie/resource_factory.rb
hyrax-4.0.0.beta2 lib/wings/valkyrie/resource_factory.rb
hyrax-3.4.2 lib/wings/valkyrie/resource_factory.rb
hyrax-4.0.0.beta1 lib/wings/valkyrie/resource_factory.rb
hyrax-3.4.1 lib/wings/valkyrie/resource_factory.rb
hyrax-3.4.0 lib/wings/valkyrie/resource_factory.rb
hyrax-3.3.0 lib/wings/valkyrie/resource_factory.rb
hyrax-3.2.0 lib/wings/valkyrie/resource_factory.rb
hyrax-3.1.0 lib/wings/valkyrie/resource_factory.rb
hyrax-3.0.2 lib/wings/valkyrie/resource_factory.rb