Sha256: e77f307d4efa34da091949a81860739d735189e8e12de26a37fc7e5e9a587e41
Contents?: true
Size: 1.11 KB
Versions: 22
Compression:
Stored size: 1.11 KB
Contents
require 'noid' module Sufia module IdService def self.noid_template Sufia.config.noid_template end @minter = ::Noid::Minter.new(template: noid_template) @pid = $$ @namespace = Sufia.config.id_namespace @semaphore = Mutex.new def self.valid?(identifier) # remove the fedora namespace since it's not part of the noid noid = identifier.split(":").last return @minter.valid? noid end def self.mint @semaphore.synchronize do while true pid = self.next_id return pid unless ActiveFedora::Base.exists?(pid) end end end protected def self.next_id pid = '' File.open(Sufia.config.minter_statefile, File::RDWR|File::CREAT, 0644) do |f| f.flock(File::LOCK_EX) yaml = YAML::load(f.read) yaml = {template: noid_template} unless yaml minter = ::Noid::Minter.new(yaml) pid = "#{@namespace}:#{minter.mint}" f.rewind yaml = YAML::dump(minter.dump) f.write yaml f.flush f.truncate(f.pos) end return pid end end end
Version data entries
22 entries across 22 versions & 2 rubygems