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

pulibrary / pdc_describe / 9dbcf7a4-1c56-4510-9614-74ad5a22cff6

31 Jul 2024 02:46PM UTC coverage: 1.08% (-95.1%) from 96.17%
9dbcf7a4-1c56-4510-9614-74ad5a22cff6

push

circleci

jrgriffiniii
wip

52 of 4814 relevant lines covered (1.08%)

0.01 hits per line

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

0.0
/app/models/readme.rb
1
# frozen_string_literal: true
2
class Readme
×
3
  attr_reader :work, :current_user
×
4

5
  def initialize(work, current_user)
×
6
    @work = work
×
7
    @current_user = current_user
×
8
  end
×
9

10
  def attach(readme_file_param)
×
11
    return "A README file is required!" if readme_file_param.blank? && blank?
×
12
    return nil if readme_file_param.blank?
×
13
    remove_old_readme
×
14

15
    key = upload_readme(readme_file_param)
×
16
    if key
×
17
      @file_names = [readme_file_param.original_filename]
×
18
      @s3_readme_idx = 0
×
19
      log_changes
×
20
      nil
×
21
    else
×
22
      "An error uploading your README was encountered.  Please try again."
×
23
    end
×
24
  end
×
25

26
  def blank?
×
27
    s3_readme_idx.nil?
×
28
  end
×
29

30
  def file_name
×
31
    return nil if blank?
×
32
    file_names[s3_readme_idx]
×
33
  end
×
34

35
    private
×
36

37
      def s3_readme_idx
×
38
        @s3_readme_idx ||= file_names.find_index { |file_name| file_name.upcase.include?("README") }
×
39
      end
×
40

41
      def file_names
×
42
        @file_names ||= work.pre_curation_uploads.map(&:filename_display)
×
43
      end
×
44

45
      def remove_old_readme
×
46
        return if blank?
×
47
        work.s3_query_service.delete_s3_object(work.pre_curation_uploads[s3_readme_idx].key)
×
48
      end
×
49

50
      def upload_readme(readme_file_param)
×
51
        readme_name = readme_file_param.original_filename
×
52
        size = readme_file_param.size
×
53
        work.s3_query_service.upload_file(io: readme_file_param.to_io, filename: readme_name, size:)
×
54
      end
×
55

56
      def log_changes
×
57
        work.s3_query_service.client_s3_files(reload: true)
×
58
        work.reload_snapshots(user_id: current_user.id)
×
59
      end
×
60
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