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

pulibrary / pdc_describe / 9091a1ae-29be-458c-984a-339d213919c4

12 Dec 2024 07:41PM UTC coverage: 26.434% (-69.7%) from 96.113%
9091a1ae-29be-458c-984a-339d213919c4

Pull #2000

circleci

jrgriffiniii
Removing integration with ActiveStorage
Pull Request #2000: Bump actionpack from 7.2.1.1 to 7.2.2.1

945 of 3575 relevant lines covered (26.43%)

0.35 hits per line

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

34.88
/app/models/ark.rb
1
# frozen_string_literal: true
2
require "ezid-client"
1✔
3

4
class Ark
1✔
5
  EZID_TEST_SHOULDER = "ark:/99999"
1✔
6

7
  # Mints a new EZID identifier, returns the id (e.g. "ark:/99999/fk4tq65d6k")
8
  def self.mint
1✔
9
    identifier = Ezid::Identifier.mint
×
10
    identifier.id
×
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"
16
  def self.format_ark(ark)
1✔
17
    return ark if ark.starts_with?("ark:/")
×
18
    "ark:/#{ark}"
×
19
  end
20

21
  def self.find(ezid)
1✔
22
    Ezid::Identifier.find(format_ark(ezid))
×
23
  rescue StandardError => error
24
    Rails.logger.error("Failed to find the EZID #{ezid}: #{error.class}: #{error.message}")
×
25
    nil
×
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
34
  def self.update(ezid, new_url, command_line: false)
1✔
35
    return if ezid.start_with?(EZID_TEST_SHOULDER)
×
36
    Retryable.retryable(tries: 5, sleep: 3, on: [Net::HTTPServerException]) do
×
37
      identifier = Ezid::Identifier.find(ezid)
×
38
      if identifier.target != new_url
×
39
        identifier.target = new_url
×
40
        identifier.save
×
41
      end
42
    end
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)
×
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]
53
  def self.valid?(ezid)
1✔
54
    # Always consider test ARKs valid
55
    return true if ezid.start_with?(EZID_TEST_SHOULDER)
×
56
    # Try and retrieve the ARK
57
    new(ezid)
×
58
    true
×
59
  rescue ArgumentError
60
    false
×
61
  end
62

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

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

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

76
  delegate :id, :metadata, to: :object
1✔
77

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

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

86
  def save!
1✔
87
    object.modify(id, metadata)
×
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
  # ======================
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