• 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/s3_file.rb
1
# frozen_string_literal: true
UNCOV
2
class S3File
×
UNCOV
3
  include Rails.application.routes.url_helpers
×
UNCOV
4
  include ActionView::Helpers::NumberHelper
×
5

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

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

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

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

UNCOV
35
  def created_at
×
UNCOV
36
    last_modified
×
UNCOV
37
  end
×
38

UNCOV
39
  def byte_size
×
UNCOV
40
    size
×
UNCOV
41
  end
×
42

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

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

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

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

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

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

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

77
    persisted
×
UNCOV
78
  end
×
79

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

UNCOV
87
  private
×
88

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

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