Class: Noid::Rails::Minter::Base Abstract

Inherits:
Minter
  • Object
show all
Defined in:
lib/noid/rails/minter/base.rb

Overview

This class is abstract.

the base class for minters

Direct Known Subclasses

Db, File

Instance Method Summary collapse

Constructor Details

#initialize(template = default_template) ⇒ Base

Returns a new instance of Base.

Parameters:

  • template (#to_s) (defaults to: default_template)

    a NOID template

See Also:

  • Template


13
14
15
# File 'lib/noid/rails/minter/base.rb', line 13

def initialize(template = default_template)
  super(template: template.to_s)
end

Instance Method Details

#mintString

Sychronously mint a new identifier.

Returns:

  • (String)

    the minted identifier



21
22
23
24
25
26
27
28
# 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

#readHash{Symbol => String, Object}

Returns representation of the current minter state.

Returns:

  • (Hash{Symbol => String, Object})

    representation of the current minter state

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/noid/rails/minter/base.rb', line 32

def read
  raise NotImplementedError, 'Implement #read in child class'
end

#write!(_) ⇒ void

This method returns an undefined value.

Updates the minter state to that of the ‘minter` parameter.

Parameters:

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/noid/rails/minter/base.rb', line 41

def write!(_)
  raise NotImplementedError, 'Implement #write! in child class'
end