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

pulibrary / pdc_discovery / 5af13607-7741-41ac-b110-c94c8a3ee0f0

pending completion
5af13607-7741-41ac-b110-c94c8a3ee0f0

Pull #441

circleci

hectorcorrea
Better error handling
Pull Request #441: Indexing to a new collection

99 of 99 new or added lines in 3 files covered. (100.0%)

1816 of 2220 relevant lines covered (81.8%)

95.45 hits per line

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

68.75
/app/models/dataset_file.rb
1
# frozen_string_literal: true
2

3
class DatasetFile
1✔
4
  attr_accessor :name, :description, :format, :size, :mime_type, :sequence, :handle, :extension,
1✔
5
    :source, :download_url
6

7
  def self.from_hash(data, data_source)
1✔
8
    if data_source == "pdc_describe"
4✔
9
      from_hash_describe(data)
×
10
    else
11
      from_hash_dataspace(data)
4✔
12
    end
13
  end
14

15
  def self.from_hash_dataspace(data)
1✔
16
    hash = data.with_indifferent_access
4✔
17
    file = DatasetFile.new
4✔
18
    file.source = "dataspace"
4✔
19
    file.name = hash[:name]
4✔
20
    file.extension = File.extname(file.name)
4✔
21
    file.extension = file.extension[1..] if file.extension != "." # drop the leading period
4✔
22
    file.description = hash[:description]
4✔
23
    file.mime_type = hash[:mime_type]
4✔
24
    file.size = hash[:size]
4✔
25
    file.sequence = (hash[:sequence] || "").to_i
4✔
26
    # Technically the handle is a property of the dataset item rather than the file (aka bitstream)
27
    # but we store it at the file level for convenience.
28
    file.handle = hash[:handle]
4✔
29
    file.download_url = "#{DatasetFile.download_root}/#{file.handle}/#{file.sequence}/#{file.name}"
4✔
30
    file
4✔
31
  end
32

33
  def self.from_hash_describe(data)
1✔
34
    hash = data.with_indifferent_access
×
35
    file = DatasetFile.new
×
36
    file.source = "pdc_describe"
×
37
    file.name = hash[:name]
×
38
    file.extension = File.extname(file.name)
×
39
    file.extension = file.extension[1..] if file.extension != "." # drop the leading period
×
40
    file.size = hash[:size]
×
41
    file.download_url = hash[:url]
×
42
    file
×
43
  end
44

45
  def self.download_root
1✔
46
    "#{Rails.configuration.pdc_discovery.dataspace_url}/bitstream"
4✔
47
  end
48
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