From 4a13ae26da12daa2479be68506e3cd9cc5f51a98 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Fri, 31 Aug 2018 10:19:27 -0500 Subject: [PATCH] Allow for a pluggable minter service (#1295) --- lib/active_fedora/persistence.rb | 15 ++++++++++++++- .../persistence/null_identifier_service.rb | 11 +++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 lib/active_fedora/persistence/null_identifier_service.rb diff --git a/lib/active_fedora/persistence.rb b/lib/active_fedora/persistence.rb index b10aac0d3..56d40936f 100644 --- a/lib/active_fedora/persistence.rb +++ b/lib/active_fedora/persistence.rb @@ -2,6 +2,13 @@ module ActiveFedora # = Active Fedora Persistence module Persistence extend ActiveSupport::Concern + extend ActiveSupport::Autoload + autoload :NullIdentifierService + + included do + class_attribute :identifier_service_class + self.identifier_service_class = NullIdentifierService + end def new_record? return true if @ldp_source.subject.nil? @@ -209,7 +216,13 @@ def execute_sparql_update end # Override to tie in an ID minting service - def assign_id; end + def assign_id + identifier_service.mint + end + + def identifier_service + @identifier_service ||= identifier_service_class.new + end # This is only used when creating a new record. If the object doesn't have an id # and assign_id can mint an id for the object, then assign it to the resource. diff --git a/lib/active_fedora/persistence/null_identifier_service.rb b/lib/active_fedora/persistence/null_identifier_service.rb new file mode 100644 index 000000000..3be1743f2 --- /dev/null +++ b/lib/active_fedora/persistence/null_identifier_service.rb @@ -0,0 +1,11 @@ +module ActiveFedora + module Persistence + # An identifier service that doesn't mint IDs, so that the autocreated + # identifiers from Fedora will be used. + class NullIdentifierService + # Effectively a no-op + # @return [NilClass] + def mint; end + end + end +end