Skip to content

Commit

Permalink
Allow for a pluggable minter service (#1295)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne authored and awead committed Aug 31, 2018
1 parent e6df20c commit 4a13ae2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/active_fedora/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions lib/active_fedora/persistence/null_identifier_service.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4a13ae2

Please sign in to comment.