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

pulibrary / bibdata / b3c4a532-5da0-46f8-9c20-20018605a028

21 Mar 2025 08:11PM UTC coverage: 42.257% (-49.9%) from 92.185%
b3c4a532-5da0-46f8-9c20-20018605a028

push

circleci

sandbergja
Move various gems from the default Gemfile group to a more appropriate group

1599 of 3784 relevant lines covered (42.26%)

2.56 hits per line

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

27.94
/app/models/dump_file.rb
1
require 'zlib'
1✔
2
require 'digest'
1✔
3
require 'rubygems/package'
1✔
4

5
class DumpFile < ActiveRecord::Base
1✔
6
  belongs_to :dump
1✔
7
  enum index_status: { enqueued: 0, started: 1, done: 2 }
1✔
8

9
  enum dump_file_type: {
1✔
10
    bib_records: 1,
11
    updated_records: 2,
12
    recap_records: 3,
13
    recap_records_full: 4,
14
    log_file: 5,
15
    new_records: 6,
16
    merged_ids: 7,
17
    bib_ids: 8,
18
    recap_records_full_metadata: 9
19
  }
20

21
  after_create do
1✔
22
    self.path = generate_fp if path.nil?
×
23
    save
×
24
  end
25

26
  before_save do
1✔
27
    unless path.nil? || !File.exist?(path) || md5.present?
×
28
      self.md5 = File.open(path, 'rb') do |io|
×
29
        # nosemgrep
30
        digest = Digest::MD5.new
×
31
        buf = ''
×
32
        digest.update(buf) while io.read(4096, buf)
×
33
        digest
×
34
      end
35
    end
36
  end
37

38
  before_destroy do
1✔
39
    File.delete(path) if File.exist?(path)
×
40
  end
41

42
  def recap_record_type?
1✔
43
    self.recap_records? || self.recap_records_full?
×
44
  end
45

46
  def zipped?
1✔
47
    path.ends_with?('.gz')
×
48
  end
49

50
  def zip
1✔
51
    unless zipped?
×
52
      gz_path = "#{path}.gz"
×
53
      uncompressed_path = path
×
54
      Zlib::GzipWriter.open(gz_path) do |gz|
×
55
        File.open(uncompressed_path) do |fp|
×
56
          while chunk = fp.read(16 * 1024)
×
57
            gz.write chunk
×
58
          end
59
        end
60
        gz.close
×
61
      end
62
      self.path = gz_path
×
63
      File.delete(uncompressed_path)
×
64
      save
×
65
    end
66
    self
×
67
  end
68

69
  def unzip
1✔
70
    if zipped?
×
71
      uncompressed_path = path.sub(/\.gz$/, '')
×
72
      gz_path = path
×
73

74
      Zlib::GzipReader.open(gz_path) do |gz|
×
75
        File.open(uncompressed_path, 'wb') do |fp|
×
76
          while chunk = gz.read(16 * 1024)
×
77
            fp.write chunk
×
78
          end
79
        end
80
        gz.close
×
81
      end
82

83
      self.path = uncompressed_path
×
84
      File.delete(gz_path)
×
85
      save
×
86
    end
87
    self
×
88
  end
89

90
  def generate_fp
1✔
91
    File.join(MARC_LIBERATION_CONFIG['data_dir'], Time.now.to_i.to_s)
×
92
  end
93

94
  # Alma files are tarred and g-zipped, so you have to do both.
95
  def tar_decompress_file
1✔
96
    tar_reader.each.map do |entry|
×
97
      Tempfile.create(decompressed_filename(entry), binmode: true) do |decompressed_tmp|
×
98
        decompressed_file = write_chunks(entry, decompressed_tmp)
×
99
        entry.close
×
100
        yield(decompressed_file)
×
101
      end
102
    end
103
  end
104

105
  def tar_reader
1✔
106
    tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(path))
×
107
    tar_extract.tap(&:rewind)
×
108
  end
109

110
  def write_chunks(entry, temp_file)
1✔
111
    while (chunk = entry.read(16 * 1024))
×
112
      temp_file.write chunk
×
113
    end
114
    temp_file.tap(&:rewind)
×
115
  end
116

117
  def decompressed_filename(entry)
1✔
118
    file_name, decompress_extension = entry.full_name.split('.')
×
119
    decompress_extension ||= 'xml'
×
120
    ["full_reindex_file_unzip_#{file_name}", '.' + decompress_extension]
×
121
  end
122
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