class Noid::Rails::Minter::Base
@abstract the base class for minters
Public Class Methods
new(template = default_template)
click to toggle source
@param template [#to_s] a NOID template @see Noid::Template
Calls superclass method
# File lib/noid/rails/minter/base.rb, line 13 def initialize(template = default_template) super(template: template.to_s) end
Public Instance Methods
mint()
click to toggle source
Sychronously mint a new identifier.
@return [String] the minted identifier
# File lib/noid/rails/minter/base.rb, line 21 def mint Mutex.new.synchronize do loop do pid = next_id return pid unless identifier_in_use?(pid) end end end
read()
click to toggle source
@return [Hash{Symbol => String, Object}] representation of the current minter state
# File lib/noid/rails/minter/base.rb, line 32 def read raise NotImplementedError, 'Implement #read in child class' end
write!(_)
click to toggle source
Updates the minter state to that of the `minter` parameter.
@param minter [Minter::Base] @return [void]
# File lib/noid/rails/minter/base.rb, line 41 def write!(_) raise NotImplementedError, 'Implement #write! in child class' end
Private Instance Methods
default_template()
click to toggle source
@return [#to_s] the default template for this
# File lib/noid/rails/minter/base.rb, line 53 def default_template Noid::Rails.config.template end
identifier_in_use?(id)
click to toggle source
# File lib/noid/rails/minter/base.rb, line 47 def identifier_in_use?(id) Noid::Rails.config.identifier_in_use.call(id) end
next_id()
click to toggle source
@return [String] a new identifier
# File lib/noid/rails/minter/base.rb, line 59 def next_id raise NotImplementedError, 'Implement #next_id in child class' end