• 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

38.6
/app/models/s3_file.rb
1
# frozen_string_literal: true
2
class S3File
1✔
3
  include Rails.application.routes.url_helpers
1✔
4
  include ActionView::Helpers::NumberHelper
1✔
5

6
  attr_accessor :safe_id, :filename, :last_modified, :size, :checksum, :url, :filename_display, :last_modified_display, :display_size, :is_folder
1✔
7
  alias key filename
1✔
8
  alias id filename
1✔
9

10
  def self.from_json(json_string)
1✔
11
    json = if json_string.is_a? String
×
12
             JSON.parse(json_string)
×
13
           else
14
             json_string
×
15
           end
16

17
    new(filename: json["filename"], last_modified: DateTime.parse(json["last_modified"]), size: json["size"],
×
18
        checksum: json["checksum"], work: Work.find(json["work_id"]), filename_display: json["filename_display"], url: json["url"])
19
  end
20

21
  def initialize(filename:, last_modified:, size:, checksum:, work:, filename_display: nil, url: nil)
1✔
22
    @safe_id = filename_as_id(filename)
×
23
    @filename = filename
×
24
    @filename_display = filename_display || filename_short(work, filename)
×
25
    @last_modified = last_modified
×
26
    @last_modified_display = last_modified.in_time_zone.strftime("%m/%d/%Y %I:%M %p") # mm/dd/YYYY HH:MM AM
×
27
    @size = size
×
28
    @display_size = number_to_human_size(size)
×
29
    @checksum = checksum.delete('"')
×
30
    @url = url || work_download_path(work, filename:)
×
31
    @work = work
×
32
    @is_folder = filename.ends_with?("/")
×
33
  end
34

35
  def created_at
1✔
36
    last_modified
×
37
  end
38

39
  def byte_size
1✔
40
    size
×
41
  end
42

43
  def directory?
1✔
44
    size == 0
×
45
  end
46

47
  def empty?
1✔
48
    size == 0
×
49
  end
50

51
  def globus_url
1✔
52
    encoded_filename = filename.split("/").map { |name| ERB::Util.url_encode(name) }.join("/")
×
53
    File.join(Rails.configuration.globus["post_curation_base_url"], encoded_filename)
×
54
  end
55

56
  delegate :s3_query_service, to: :@work
1✔
57
  delegate :bucket_name, to: :s3_query_service
1✔
58
  def s3_client
1✔
59
    s3_query_service.client
×
60
  end
61

62
  # Create a new snapshot of the current upload
63
  # @return [UploadSnapshot]
64
  def create_snapshot
1✔
65
    created = UploadSnapshot.create(url:, work: @work, files: [{ filename:, checksum: }])
×
66

67
    created.upload = self
×
68
    created.save
×
69
    created.reload
×
70
  end
71

72
  # @return [UploadSnapshot]
73
  def snapshots
1✔
74
    persisted = UploadSnapshot.where(key:, url:, work: @work)
×
75
    return [] if persisted.blank?
×
76

77
    persisted
×
78
  end
79

80
  def to_json
1✔
81
    {
82
      filename:, last_modified:, size:,
×
83
      checksum:, work_id: @work.id, filename_display:, url:
84
    }.to_json
85
  end
86

87
  private
1✔
88

89
    # Filename without the DOI/work-id/ in the path (but we preserve other path information if there is any)
90
    def filename_short(work, filename)
1✔
91
      prefix = "#{work.doi}/#{work.id}/"
×
92
      if filename.start_with?(prefix)
×
93
        filename[prefix.length..]
×
94
      else
95
        filename
×
96
      end
97
    end
98

99
    def filename_as_id(filename)
1✔
100
      # The full filename and path but only with alphanumeric characters
101
      # everything else becomes as dash.
102
      filename.gsub(/[^A-Za-z\d]/, "-")
×
103
    end
104
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