Sha256: 2a27683b3126a3da773e9a581a8af210fb6b2c86f05cd86f8d80c43ccc980a85
Contents?: true
Size: 1.08 KB
Versions: 7
Compression:
Stored size: 1.08 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 id = '' 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) id = minter.mint f.rewind yaml = YAML::dump(minter.dump) f.write yaml f.flush f.truncate(f.pos) end id end end end
Version data entries
7 entries across 7 versions & 2 rubygems