Skip to content

Instantly share code, notes, and snippets.

@dchandekstark
Created December 17, 2014 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dchandekstark/bfc609d9516b57f1ed7f to your computer and use it in GitHub Desktop.
Save dchandekstark/bfc609d9516b57f1ed7f to your computer and use it in GitHub Desktop.
ActiveFedore attribute w/multiple: false setting to ActiveTriples::Resource
require "rdf-vocab"
module Ddr
module Metadata
class Identifier < ActiveTriples::Resource
PREMIS = Ddr::Vocab::PREMIS
ARK_RE = /^ark:/
DOI_RE = /^doi:/
ARK = Ddr::Vocab::Preservation.ark
DOI = RDF::Vocab::Identifiers.doi
configure type: PREMIS.Identifier
property :value, predicate: PREMIS.hasIdentifierValue
property :type, predicate: PREMIS.hasIdentifierType
def to_s
value.first
end
def set_type
if value =~ ARK_RE
self.type = ARK
elsif value =~ DOI_RE
self.type = DOI
end
end
end
end
end
module Ddr
module Datastreams
class PreservationMetadataDatastream < ActiveFedora::NtriplesRDFDatastream
property :permanent_id, predicate: Ddr::Vocab::Preservation.hasPermanentId,
class_name: "Ddr::Metadata::Identifier"
property :permanent_url, predicate: Ddr::Vocab::Preservation.hasPermanentUrl
end
end
end
module Ddr
module Models
module HasPreservationMetadata
extend ActiveSupport::Concern
included do
has_metadata "preservationMetadata",
type: Ddr::Datastreams::PreservationMetadataDatastream,
versionable: true,
control_group: "M"
has_attributes :permanent_id, :permanent_url,
datastream: "preservationMetadata", multiple: false
after_create :assign_permanent_id!
end
def permanent_id_manager
@permanent_id_manager ||= Ddr::Managers::PermanentIdManager.new(self)
end
def assign_permanent_id!
permanent_id_manager.assign_later
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment