Skip to content

Commit

Permalink
fixes for standardrb
Browse files Browse the repository at this point in the history
  • Loading branch information
aelkiss committed May 21, 2024
1 parent cde814e commit 9d83845
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 38 deletions.
4 changes: 2 additions & 2 deletions lib/basic_query_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class BasicQueryReport
# Usage:
# query = { ... }
# BasicQueryReport.new.aggregate(query) { |result| ... }
def aggregate(query, &block)
def aggregate(query, &)
# We may have to change to allowDiskUse if/when we upgrade Mongo & mongo drivers,
# because that seems like the more current lingo.
Cluster.collection.aggregate(query, {allow_disk_use: true}).each(&block)
Cluster.collection.aggregate(query, {allow_disk_use: true}).each(&)
end
end
3 changes: 1 addition & 2 deletions lib/concordance_validation/concordance.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "zlib"
require "pp"

# Concordance validation.
# Takes a file with <raw ocn> <tab> <resolved ocn>, checks that its ok.
Expand Down Expand Up @@ -111,7 +110,7 @@ def terminal_ocn(ocn)
resolved.each do |o|
# it is not terminal so we replace with the ocns it resolves to
if @raw_to_resolved.key? o
resolved.map! { |x| x == o ? @raw_to_resolved[o] : x }.flatten!
resolved.map! { |x| (x == o) ? @raw_to_resolved[o] : x }.flatten!
end
end
resolved.uniq!
Expand Down
4 changes: 2 additions & 2 deletions lib/data_sources/directory_locator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def base

# The holdings parent directory for the organization
def holdings
File.join(base, "print\ holdings")
File.join(base, "print holdings")
end

# The current-year holdings directory
Expand All @@ -61,7 +61,7 @@ def holdings_current

# The shared print directory (not divided into years like holdings are)
def shared_print
File.join(base, "shared\ print")
File.join(base, "shared print")
end

# This is where HT uploads reports and such for the member to access.
Expand Down
2 changes: 1 addition & 1 deletion lib/overlap/overlap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize(cluster, org, ht_item)

# These methods should return zero in the most basic case
["copy", "brt", "wd", "lm", "access"].each do |method|
define_method "#{method}_count".to_sym do
define_method :"#{method}_count" do
0
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/reports/cost_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def total_hscore(member)

[:spm, :ser, :mpm].each do |format|
# HScore for a particular format
define_method "#{format}_total".to_sym do |member|
define_method :"#{format}_total" do |member|
total = 0.0
freq_table[member.to_sym][format].each do |num_orgs, freq|
total += freq.to_f / num_orgs
Expand All @@ -208,8 +208,8 @@ def total_hscore(member)
end

# Costs for a particular format
define_method "#{format}_costs".to_sym do |member|
public_send("#{format}_total", member) * cost_per_volume
define_method :"#{format}_costs" do |member|
public_send(:"#{format}_total", member) * cost_per_volume
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/reports/etas_organization_overlap_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def initialize(organization = nil)
end

def open_report(org, date)
nonus = Services.ht_organizations[org]&.country_code == "us" ? "" : "_nonus"
nonus = (Services.ht_organizations[org]&.country_code == "us") ? "" : "_nonus"
File.open("#{local_report_path}/etas_overlap_#{org}_#{date}#{nonus}.tsv", "w")
end

Expand Down
4 changes: 2 additions & 2 deletions lib/reports/rare_uncommitted.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def output_organization
end

# We store gov_doc_flag as a true/false and the report wants 1/0.
govdoc_bool_2_int = holding.gov_doc_flag == true ? 1 : 0
govdoc_bool_2_int = (holding.gov_doc_flag == true) ? 1 : 0

record = [
holding.organization,
Expand Down Expand Up @@ -209,7 +209,7 @@ def non_sp_organizations

# The groups that @organization is a member of, if any
def in_group
@in_group ||= (@sp_groups.org_to_groups(@organization) || [])
@in_group ||= @sp_groups.org_to_groups(@organization) || []
end

# The other orgs in the groups that @organization is member of, if any
Expand Down
2 changes: 1 addition & 1 deletion lib/scrub/autoscrub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def marker
if tot_lines <= 1
raise "File #{@path} has no data? Total lines #{tot_lines}."
end
batch_size = tot_lines < 100 ? 100 : tot_lines / 100
batch_size = (tot_lines < 100) ? 100 : tot_lines / 100
Services.scrub_logger.info("File is #{tot_lines} lines long, batch size #{batch_size}")
@marker = Services.progress_tracker.call(batch_size: batch_size)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/scrub/member_holding_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ def log(msg)
Services.scrub_logger.info(msg)
end

def parse(&block)
def parse(&)
unless valid_filename?
raise Scrub::FileNameError, "Invalid filename #{@filename}"
end

scrub_stats = Services.scrub_stats
each_holding(&block)
each_holding(&)
log("Scrub stats:")
scrub_stats.keys.sort.each do |ssk|
log("#{ssk}\t#{scrub_stats[ssk]}")
Expand Down
2 changes: 1 addition & 1 deletion lib/shared_print/deprecation_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def cluster

# The cluster should have commitments.
def commitments
@commitments ||= (cluster&.commitments || [])
@commitments ||= cluster&.commitments || []
end

# Cluster should have commitments by dep.organization.
Expand Down
2 changes: 1 addition & 1 deletion lib/shared_print/updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def apply_single_update
next
end
report "updating #{k}=#{v}"
commitment.send("#{strip_new_from_symbol(k)}=", v)
commitment.send(:"#{strip_new_from_symbol(k)}=", v)
end
report "OK."
commitment.save
Expand Down
2 changes: 1 addition & 1 deletion spec/cluster_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_output_lines
# previously-persisted documents
# https://jira.mongodb.org/browse/MONGOID-5704
c = Cluster.first
doc = c.as_document
c.as_document
expect(c.valid?).to be false
expect(get_output_lines.count).to eq one_invalid_cluster_line_count
end
Expand Down
4 changes: 2 additions & 2 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ def cleanup(output)
describe "Scrub" do
it "'scrub x' loads records and produces output for org x" do
# Needs a bit of setup.
local_d = "#{ENV["TEST_TMP"]}/local_member_data/umich-hathitrust-member-data/print\ holdings/#{Time.new.year}/"
remote_d = "#{ENV["TEST_TMP"]}/remote_member_data/umich-hathitrust-member-data/print\ holdings/#{Time.new.year}/"
local_d = "#{ENV["TEST_TMP"]}/local_member_data/umich-hathitrust-member-data/print holdings/#{Time.new.year}/"
remote_d = "#{ENV["TEST_TMP"]}/remote_member_data/umich-hathitrust-member-data/print holdings/#{Time.new.year}/"
logfile = File.join(remote_d, "umich_mon_#{Time.new.strftime("%Y%m%d")}.log")
FileUtils.mkdir_p(remote_d)
FileUtils.cp("spec/fixtures/umich_mon_full_20220101.tsv", remote_d)
Expand Down
1 change: 0 additions & 1 deletion spec/reports/etas_organization_overlap_report_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require "spec_helper"
require "pp"
require "reports/etas_organization_overlap_report"

RSpec.describe Reports::EtasOrganizationOverlapReport do
Expand Down
31 changes: 15 additions & 16 deletions spec/sidekiq_jobs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
require "spec_helper"
require "sidekiq_jobs"

class TestCallback
def self.did_run
@did_run
end

def self.set_run(did_run)
@did_run = did_run
end

def on_success(status, options)
puts "Callback ran: #{status}, #{options}"
self.class.set_run(true)
Thread.exit
end
end

class FakeJob
def initialize(required, optional = "default", kw_required:, kw_optional: "default")
Expand Down Expand Up @@ -47,22 +62,6 @@ def run
end

it "can batch jobs and call callbacks" do
class TestCallback
def self.did_run
@did_run
end

def self.set_run(did_run)
@did_run = did_run
end

def on_success(status, options)
puts "Callback ran: #{status}, #{options}"
self.class.set_run(true)
Thread.exit
end
end

Sidekiq::Testing.disable! do
TestCallback.set_run(false)

Expand Down

0 comments on commit 9d83845

Please sign in to comment.