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

pulibrary / pdc_describe / cace366a-ffad-45f1-9b60-678e607fa527

14 May 2024 02:21PM UTC coverage: 60.862% (-35.0%) from 95.908%
cace366a-ffad-45f1-9b60-678e607fa527

push

circleci

jrgriffiniii
wip

1 of 3 new or added lines in 2 files covered. (33.33%)

1194 existing lines in 57 files now uncovered.

2076 of 3411 relevant lines covered (60.86%)

22.71 hits per line

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

66.07
/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
1✔
7
  alias key filename
1✔
8
  alias id filename
1✔
9

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

UNCOV
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)
6✔
23
    @filename = filename
6✔
24
    @filename_display = filename_display || filename_short(work, filename)
6✔
25
    @last_modified = last_modified
6✔
26
    @last_modified_display = last_modified.in_time_zone.strftime("%m/%d/%Y %I:%M %p") # mm/dd/YYYY HH:MM AM
6✔
27
    @size = size
6✔
28
    @display_size = number_to_human_size(size)
6✔
29
    @checksum = checksum.delete('"')
6✔
30
    @url = url || work_download_path(work, filename:)
6✔
31
    @work = work
6✔
32
  end
33

34
  def created_at
1✔
35
    last_modified
4✔
36
  end
37

38
  def byte_size
1✔
39
    size
×
40
  end
41

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

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

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

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

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

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

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

76
    persisted
×
77
  end
78

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

86
  private
1✔
87

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

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