Class: ActiveFedora::Noid::Minter::Base

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

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:

  • Noid::Template


12
13
14
# File 'lib/active_fedora/noid/minter/base.rb', line 12

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

Instance Method Details

#mintString

Sychronously mint a new identifier. Guarantees the ID is not already reserved in ActiveFedora.

Returns:

  • (String)

    the minted identifier



20
21
22
23
24
25
26
27
# File 'lib/active_fedora/noid/minter/base.rb', line 20

def mint
  Mutex.new.synchronize do
    loop do
      pid = next_id
      return pid unless ActiveFedora::Base.exists?(pid) || ActiveFedora::Base.gone?(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)


31
32
33
# File 'lib/active_fedora/noid/minter/base.rb', line 31

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)


40
41
42
# File 'lib/active_fedora/noid/minter/base.rb', line 40

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