• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / pdc_describe / 4e4e59fc-9df4-4838-9fd4-6c7ea33cdb7c

07 Apr 2025 06:36PM UTC coverage: 1.283% (-94.6%) from 95.862%
4e4e59fc-9df4-4838-9fd4-6c7ea33cdb7c

Pull #1994

circleci

hectorcorrea
Switched to use the autocomplete that we aleady use for ROR. Integrated it with the existing logic for creators
Pull Request #1994: Started adding auto complete to contributors

0 of 46 new or added lines in 2 files covered. (0.0%)

4806 existing lines in 74 files now uncovered.

65 of 5065 relevant lines covered (1.28%)

0.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/models/ark.rb
1
# frozen_string_literal: true
UNCOV
2
require "ezid-client"
×
3

UNCOV
4
class Ark
×
UNCOV
5
  EZID_TEST_SHOULDER = "ark:/99999"
×
6

7
  # Mints a new EZID identifier, returns the id (e.g. "ark:/99999/fk4tq65d6k")
UNCOV
8
  def self.mint
×
UNCOV
9
    identifier = Ezid::Identifier.mint
×
UNCOV
10
    identifier.id
×
UNCOV
11
  end
×
12

13
  ##
14
  # Ezid::Identifier.find(ezid) only works if the ezid is formatted as an ark,
15
  # e.g., "ark:/99999/abc123"
UNCOV
16
  def self.format_ark(ark)
×
UNCOV
17
    return ark if ark.starts_with?("ark:/")
×
UNCOV
18
    "ark:/#{ark}"
×
UNCOV
19
  end
×
20

UNCOV
21
  def self.find(ezid)
×
UNCOV
22
    Ezid::Identifier.find(format_ark(ezid))
×
UNCOV
23
  rescue StandardError => error
×
UNCOV
24
    Rails.logger.error("Failed to find the EZID #{ezid}: #{error.class}: #{error.message}")
×
UNCOV
25
    nil
×
UNCOV
26
  end
×
27

28
  # Update the ARK to point to a new target.
29
  # Sometimes we get an error:
30
  # Net::HTTPServerException: 400 "Bad Request"
31
  # If that happens, try again, up to 5 times, sleep 3 seconds between retries.
32
  # If it still fails, send the error to honeybadger.
33
  # @note No testing coverage for StandardError but depends on API
UNCOV
34
  def self.update(ezid, new_url, command_line: false)
×
UNCOV
35
    return if ezid.start_with?(EZID_TEST_SHOULDER)
×
UNCOV
36
    Retryable.retryable(tries: 5, sleep: 3, on: [Net::HTTPServerException]) do
×
UNCOV
37
      identifier = Ezid::Identifier.find(ezid)
×
UNCOV
38
      if identifier.target != new_url
×
UNCOV
39
        identifier.target = new_url
×
UNCOV
40
        identifier.save
×
UNCOV
41
      end
×
UNCOV
42
    end
×
UNCOV
43
  rescue StandardError => error
×
44
    message = "Unable to update EZID #{ezid}: #{error.class}: #{error.message}"
×
45
    puts message if command_line
×
46
    Rails.logger.error(message)
×
47
    Honeybadger.notify(message)
×
UNCOV
48
  end
×
49

50
  # Determines whether or not a given EZID string is a valid ARK
51
  # @param [ezid] [String] the EZID being validated
52
  # @return [Boolean]
UNCOV
53
  def self.valid?(ezid)
×
54
    # Always consider test ARKs valid
UNCOV
55
    return true if ezid.start_with?(EZID_TEST_SHOULDER)
×
56
    # Try and retrieve the ARK
UNCOV
57
    new(ezid)
×
UNCOV
58
    true
×
UNCOV
59
  rescue ArgumentError
×
UNCOV
60
    false
×
UNCOV
61
  end
×
62

UNCOV
63
  def self.valid_shoulder?(ezid)
×
UNCOV
64
    ezid.exclude?(self::EZID_TEST_SHOULDER)
×
UNCOV
65
  end
×
66

UNCOV
67
  def initialize(ezid)
×
UNCOV
68
    @object = self.class.find(ezid)
×
UNCOV
69
    raise(ArgumentError, "Invalid EZID provided for an ARK: #{ezid}") if @object.nil? || !self.class.valid_shoulder?(ezid)
×
UNCOV
70
  end
×
71

UNCOV
72
  def object
×
UNCOV
73
    @object ||= self.class.find(ezid)
×
UNCOV
74
  end
×
75

UNCOV
76
  delegate :id, :metadata, to: :object
×
77

UNCOV
78
  def target
×
UNCOV
79
    metadata[Ezid::Metadata::TARGET]
×
UNCOV
80
  end
×
81

UNCOV
82
  def target=(value)
×
UNCOV
83
    metadata[Ezid::Metadata::TARGET] = value
×
UNCOV
84
  end
×
85

UNCOV
86
  def save!
×
UNCOV
87
    object.modify(id, metadata)
×
UNCOV
88
  end
×
89

90
  # ======================
91
  # If in the future we want to update the information of the ARK we can
92
  # implement a few methods as follow:
93
  #
94
  # Update the target URL of the ARK to point to a new URL
95
  # def self.update_target(id, new_url)
96
  #   identifier = Ezid::Identifier.find(id)
97
  #   identifier.target = new_url
98
  #   identifier.save
99
  # end
100
  #
101
  # Update the metadata for an ARK. See https://ezid.cdlib.org/doc/apidoc.html#metadata-profiles
102
  # for details on the profiles supported.
103
  #
104
  # def self.update_metadata(id)
105
  #   metadata = {
106
  #     profile: 'dc',
107
  #     dc_creator: 'somebody',
108
  #     dc_title: 'some title',
109
  #     dc_date: '2022-04-08',
110
  #   }
111
  #   identifier = Ezid::Identifier.modify(id, metadata)
112
  # end
113
  # ======================
UNCOV
114
end
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc