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

pulibrary / bibdata / 1dcebae2-3318-4e77-bc53-82276e293354

02 May 2025 04:45PM UTC coverage: 28.256% (-63.9%) from 92.189%
1dcebae2-3318-4e77-bc53-82276e293354

push

circleci

sandbergja
Add basic infrastructure for compiling rust code

* Add a rake compile task to compile
* Run the rake task in CI
* Run the rake task before rspec tests with the rust tag, to provide quick feedback on rust changes in TDD cycles

2 of 7 new or added lines in 2 files covered. (28.57%)

2467 existing lines in 97 files now uncovered.

1089 of 3854 relevant lines covered (28.26%)

0.29 hits per line

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

19.05
/app/models/scsb/partner_updates/update.rb
1
require 'marc_cleanup'
1✔
2

3
module Scsb
1✔
4
  class PartnerUpdates
1✔
5
    class Update
1✔
6
      attr_accessor :dump
1✔
7

8
      def initialize(dump:, dump_file_type:, timestamp:)
1✔
UNCOV
9
        @last_dump = timestamp
×
UNCOV
10
        @dump = dump
×
UNCOV
11
        @dump_file_type = dump_file_type
×
UNCOV
12
        @s3_bucket = Scsb::S3Bucket.partner_transfer_client
×
UNCOV
13
        @scsb_file_dir = ENV['SCSB_FILE_DIR']
×
UNCOV
14
        @update_directory = ENV['SCSB_PARTNER_UPDATE_DIRECTORY'] || '/tmp/updates'
×
15
      end
16

17
      def attach_dump_file(filepath, dump_file_type: nil)
1✔
UNCOV
18
        dump_file_type ||= @dump_file_type
×
UNCOV
19
        df = DumpFile.create(dump_file_type:, path: filepath)
×
UNCOV
20
        df.zip
×
UNCOV
21
        df.save
×
UNCOV
22
        @dump.dump_files << df
×
UNCOV
23
        @dump.save
×
24
      end
25

26
      def process_partner_updates(files:, file_prefix: 'scsb_update_')
1✔
UNCOV
27
        xml_files = []
×
UNCOV
28
        files.each do |file|
×
UNCOV
29
          filename = File.basename(file, '.zip')
×
UNCOV
30
          filename.gsub!(/^[^_]+_([0-9]+)_([0-9]+).*$/, '\1_\2')
×
UNCOV
31
          file_increment = 1
×
UNCOV
32
          Zip::File.open(file) do |zip_file|
×
UNCOV
33
            zip_file.each do |entry|
×
UNCOV
34
              target = "#{@update_directory}/#{filename}_#{file_increment}.xml"
×
UNCOV
35
              xml_files << target
×
UNCOV
36
              entry.extract(target)
×
UNCOV
37
              file_increment += 1
×
38
            end
39
          end
UNCOV
40
          File.unlink(file)
×
41
        end
UNCOV
42
        xml_files.each do |file|
×
UNCOV
43
          filename = File.basename(file)
×
UNCOV
44
          reader = MARC::XMLReader.new(file.to_s, parser: :nokogiri)
×
UNCOV
45
          filepath = "#{@scsb_file_dir}/#{file_prefix}#{filename}"
×
UNCOV
46
          writer = MARC::XMLWriter.new(filepath)
×
UNCOV
47
          reader.each { |record| writer.write(Scsb::PartnerUpdates::Update.process_record(record)) }
×
UNCOV
48
          writer.close
×
UNCOV
49
          File.unlink(file)
×
UNCOV
50
          attach_dump_file(filepath)
×
51
        end
52
      end
53

54
      def self.process_record(record)
1✔
UNCOV
55
        record = field_delete(['856', '959'], record)
×
UNCOV
56
        record.leader[5] = 'c' if record.leader[5].eql?('d')
×
UNCOV
57
        record = bad_utf8_fix(record) if bad_utf8?(record)
×
UNCOV
58
        record = invalid_xml_fix(record) if invalid_xml_chars?(record)
×
UNCOV
59
        record = tab_newline_fix(record) if tab_newline_char?(record)
×
UNCOV
60
        record = leaderfix(record) if leader_errors?(record)
×
UNCOV
61
        record = composed_chars_normalize(record) if composed_chars_errors?(record)
×
UNCOV
62
        record = extra_space_fix(record)
×
UNCOV
63
        empty_subfield_fix(record)
×
64
      end
65

66
      def add_error(message:)
1✔
67
        error = Array.wrap(@dump.event.error)
×
68
        error << message
×
69
        @dump.event.error = error.join('; ')
×
70
        @dump.event.save
×
71
      end
72

73
      def date_strings
1✔
74
        @dump.dump_files.map do |df|
×
75
          if df.dump_file_type == 'recap_records_full_metadata'
×
76
            File.basename(df.path).split('_')[3]
×
77
          else
78
            File.basename(df.path).split('_')[2]
×
79
          end
80
        end
81
      end
82

83
      def prepare_directory
1✔
UNCOV
84
        FileUtils.mkdir_p(@update_directory)
×
85
      end
86
    end
87
  end
88
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