class ActiveFedora::Noid::Minter::File
Attributes
statefile[R]
Public Class Methods
new(template = default_template, statefile = default_statefile)
click to toggle source
Calls superclass method
ActiveFedora::Noid::Minter::Base::new
# File lib/active_fedora/noid/minter/file.rb, line 10 def initialize(template = default_template, statefile = default_statefile) @statefile = statefile super(template) end
Public Instance Methods
default_statefile()
click to toggle source
# File lib/active_fedora/noid/minter/file.rb, line 15 def default_statefile ActiveFedora::Noid.config.statefile end
read()
click to toggle source
# File lib/active_fedora/noid/minter/file.rb, line 19 def read with_file do |f| state_for(f) end end
write!(minter)
click to toggle source
# File lib/active_fedora/noid/minter/file.rb, line 25 def write!(minter) with_file do |f| # Wipe prior contents so the new state can be written from the beginning of the file f.truncate(0) f.write(Marshal.dump(minter.dump)) end end
Protected Instance Methods
next_id()
click to toggle source
# File lib/active_fedora/noid/minter/file.rb, line 50 def next_id state = read state[:template] &&= state[:template].to_s minter = ::Noid::Minter.new(state) # minter w/in the minter, lives only for an instant id = minter.mint write!(minter) id end
state_for(io_object)
click to toggle source
# File lib/active_fedora/noid/minter/file.rb, line 44 def state_for(io_object) Marshal.load(io_object.read) rescue TypeError, ArgumentError { template: template } end
with_file() { |f| ... }
click to toggle source
# File lib/active_fedora/noid/minter/file.rb, line 35 def with_file ::File.open(statefile, 'a+b', 0o644) do |f| f.flock(::File::LOCK_EX) # Files opened in append mode seek to end of file f.rewind yield f end end