Class: ArchivesSpaceArkMinter

Inherits:
ArkMinter show all
Defined in:
backend/app/lib/ark/archivesspace_ark_minter.rb

Instance Method Summary collapse

Methods inherited from ArkMinter

generate_version_key, #is_still_current?, #shoulder_for_repo, #version_key_for

Instance Method Details

#ark_recognized?(ark) ⇒ Boolean

True if the ARK has the right NAAN and has a number that falls within the range that we have already minted.

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
# File 'backend/app/lib/ark/archivesspace_ark_minter.rb', line 19

def ark_recognized?(ark)
  if ark =~ %r{/ark:/#{AppConfig[:ark_naan]}/.*?(\d+)$}
    ark_number = Integer($1)

    DB.open do |db|
      ark_number <= db[:ark_name].max(:id)
    end
  end
end

#mint!(obj, row_defaults) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'backend/app/lib/ark/archivesspace_ark_minter.rb', line 3

def mint!(obj, row_defaults)
  DB.open do |db|
    # value is not nullable, so put a temporary value in until we put the final
    # value in with the update below.
    ark_id = db[:ark_name].insert(row_defaults.merge(:ark_value => "__ark_placeholder_#{SecureRandom.hex}"))

    ark_shoulder = shoulder_for_repo(obj.repo_id)

    db[:ark_name]
      .filter(:id => ark_id)
      .update(:ark_value => build_generated_ark(ark_id, ark_shoulder))
  end
end