• 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

52.17
/app/services/location_maps_generator_service.rb
1
class LocationMapsGeneratorService
1✔
2
  def self.generate
1✔
3
    new.generate
×
4
  end
5

6
  def self.generate_from_templates
1✔
7
    new.generate_from_templates
1✔
8
  end
9

10
  attr_reader :base_path, :logger
1✔
11

12
  def initialize(base_path: Rails.root.join('marc_to_solr', 'translation_maps'), logger: Rails.logger)
1✔
13
    @base_path = base_path
1✔
14
    @logger = logger
1✔
15
  end
16

17
  def generate
1✔
18
    return unless holding_locations_table_exists?
×
19

20
    lib_display = {}
×
21
    locations_display = {}
×
22
    locations.each do |holding|
×
23
      holding_code = holding['code']
×
24
      lib_label = holding.library['label']
×
25
      # The locations.rb file needs to have the scsb locations as e.g "scsbnypl"=>"ReCAP".
26
      # This is why we are pulling the library label only for the scsb locations.
27
      # The rest of the holding_location_library records will take the holding['label'] value, even if it is blank.
28
      # This change will reflect on the holdings1_display["location"] value since it is using the locations.rb file for the location field.
29
      # see https://github.com/pulibrary/bibdata/blob/fe0a9b9495b7a8275f5a64463257c06537dd9c1e/marc_to_solr/lib/princeton_marc.rb#L653 for more info.
30
      holding_label = holding['label']
×
31
      lib_display[holding_code] = lib_label
×
32
      locations_display[holding_code] = holding_label
×
33
    end
34
    write_file('location_display.rb', lib_display)
×
35
    write_file('locations.rb', locations_display)
×
36
  end
37

38
  def generate_from_templates
1✔
39
    copy_template('locations.rb.tmpl')
1✔
40
    copy_template('location_display.rb.tmpl')
1✔
41
    copy_template('holding_library.rb.tmpl')
1✔
42
  end
43

44
  private
1✔
45

46
    def copy_template(template_name)
1✔
47
      output_file_name = template_name.gsub('.tmpl', '')
3✔
48
      output_file_path = file_path(output_file_name)
3✔
49
      template_file_path = file_path(template_name)
3✔
50
      FileUtils.cp(template_file_path, output_file_path)
3✔
51
    end
52

53
    def file_path(name)
1✔
54
      File.join(base_path, name)
6✔
55
    end
56

57
    def holding_locations_table_exists?
1✔
58
      if ActiveRecord::Base.connection.table_exists?('locations_holding_locations')
×
59
        true
×
60
      else
61
        logger.warn('Failed to seed the holding locations for Traject as the database table has not been created. Please invoke bundle exec rake db:create')
×
62
        false
×
63
      end
64
    rescue StandardError => e
65
      logger.warn("Failed to seed the holding locations for Traject due to a database error: #{e}.")
×
66
      false
×
67
    end
68

69
    def locations
1✔
70
      HoldingLocation.all
×
71
    end
72

73
    def write_file(file_name, values)
1✔
74
      path = file_path(file_name)
×
75
      File.open(path, 'w') do |file|
×
76
        PP.pp(values, file)
×
77
      end
78
    end
79
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