Skip to content

Commit

Permalink
Merge pull request #169 from collectionspace/inherit-almost-standard
Browse files Browse the repository at this point in the history
Inherit almost standard
  • Loading branch information
kspurgin authored Aug 27, 2023
2 parents c7c8f58 + 982a047 commit 2a2cc90
Show file tree
Hide file tree
Showing 39 changed files with 333 additions and 181 deletions.
4 changes: 3 additions & 1 deletion .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
# More autofixes
3d5ba8ab40d6a7f6c42690031edf91f97beeebf1
# noblame: rubocop safe autocorrects
3a8838739041df0cd40e5a0890d134141938dc16
3a8838739041df0cd40e5a0890d134141938dc16
# noblame: Rubocop safe autocorrect
0fd8bdc946c23c955fb53505776776d851d194bb
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
inherit_from:
- https://raw.githubusercontent.com/kspurgin/code-quality/main/configurations/rubocop-standard.yml
inherit_gem:
almost_standard: .rubocop.yml
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "almost_standard",
github: "kspurgin/almost_standard",
branch: "main",
group: :development

gemspec
16 changes: 12 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
GIT
remote: https://github.com/kspurgin/almost_standard.git
revision: c6e6b70f8cef16c50502f52a34f73b01ad88211a
branch: main
specs:
almost_standard (0.1.3)
bundler
rubocop
rubocop-rspec
standard

PATH
remote: .
specs:
Expand Down Expand Up @@ -155,15 +166,12 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
bundler (~> 2.3)
almost_standard!
collectionspace-mapper!
pry (~> 0.14)
rake (~> 13.0)
rspec
rubocop
rubocop-rspec
simplecov
standard
vcr (~> 6.1)
webmock

Expand Down
8 changes: 2 additions & 6 deletions collectionspace-mapper.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ Gem::Specification.new do |spec|
# The `git ls-files -z` loads the files in the RubyGem that have been
# added into git.
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject { |f|
`git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
}
end
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
Expand All @@ -56,14 +56,10 @@ Gem::Specification.new do |spec|
spec.add_dependency "xxhash", ">= 0.4.0"
spec.add_dependency "zeitwerk", "~> 2.5"

spec.add_development_dependency "bundler", "~> 2.3"
spec.add_development_dependency "pry", "~>0.14"
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec"
spec.add_development_dependency "rubocop"
spec.add_development_dependency "rubocop-rspec"
spec.add_development_dependency "simplecov"
spec.add_development_dependency "standard"
spec.add_development_dependency "vcr", "~> 6.1"
spec.add_development_dependency "webmock"
end
12 changes: 6 additions & 6 deletions lib/collectionspace/mapper/data_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def set_identifier_value
set_relation_id
else
id_field = handler.record.identifier_field
mapping = handler.record.mappings.find { |mapper|
mapping = handler.record.mappings.find do |mapper|
mapper.fieldname == id_field
}
end
thexpath = "//#{mapping.namespace}/#{mapping.fieldname}"
value = doc.xpath(thexpath).first
value = value.text
Expand Down Expand Up @@ -297,13 +297,13 @@ def map_subgroup(xpath, thisdata)
subgroup: subgroup)
end

thisdata.each { |field, subgroups|
thisdata.each do |field, subgroups|
assign_subgroup_values_to_group_hash_data(groups, field, subgroups)
}
end

groups.values.each { |grp|
groups.values.each do |grp|
create_intermediate_subgroup_hierarchy(grp, subgroup_path)
}
end

max_ct = maximum_subgroup_values(thisdata)

Expand Down
12 changes: 6 additions & 6 deletions lib/collectionspace/mapper/data_prepper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ def initially_populate_combined_data(xpath, fields)
xform = response.transformed_data

fields.each do |field, cols|
xformed = cols.map { |col|
xformed = cols.map do |col|
xform[col.datacolumn.downcase]
}.compact
end.compact
chk = []
xformed.each { |arr| chk << arr.map { |e| e.class } }
chk = chk.flatten.uniq
Expand All @@ -287,14 +287,14 @@ def initially_populate_combined_data(xpath, fields)
end

def clean_combined_data(xpath)
response.combined_data[xpath.path].select { |_fieldname, val|
response.combined_data[xpath.path].select do |_fieldname, val|
val.blank?
}.keys.each do |fieldname|
end.keys.each do |fieldname|
response.combined_data[xpath.path].delete(fieldname)
unless fieldname == "shortIdentifier"
xpath.mappings.delete_if { |mapping|
xpath.mappings.delete_if do |mapping|
mapping.fieldname == fieldname
}
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/collectionspace/mapper/data_quality_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def validate_all_refnames
end

def validate_refnames(refnames)
refnames.each { |val|
refnames.each do |val|
validate_refname(val) unless val.blank? || val == "%NULLVALUE%"
}
end
end

# @todo Use client refname parser to validate instead of a regexp
Expand Down
4 changes: 2 additions & 2 deletions lib/collectionspace/mapper/date_details/data_prepper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ def extract_dates(max)
end

def extracted_date(index)
response.transformed_data.map { |field, values|
response.transformed_data.map do |field, values|
[field, values[index]]
}.to_h
end.to_h
.compact
end

Expand Down
4 changes: 2 additions & 2 deletions lib/collectionspace/mapper/dates/structured_date_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def call(date_string)
date_string,
handler
)
elsif service_parseable_month_formats.any? { |re|
elsif service_parseable_month_formats.any? do |re|
date_string.match?(re)
}
end
CollectionSpace::Mapper::Dates::ServicesParser.new(
date_string,
handler
Expand Down
4 changes: 2 additions & 2 deletions lib/collectionspace/mapper/find_replace_transformer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ module Mapper
class FindReplaceTransformer < Transformer
def initialize(transform:)
super
@operations = transform.map { |operation|
@operations = transform.map do |operation|
FindReplaceOperation.create(operation)
}
end
end

def transform(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def get_rec_csid(id, type)

def transform_terms
%w[item1_id item2_id].each_with_index do |field, i|
transformed = response.split_data[field].map { |id|
transformed = response.split_data[field].map do |id|
get_rec_csid(id, types[i])
}
end
response.transformed_data[field] = transformed
end

Expand Down
4 changes: 2 additions & 2 deletions lib/collectionspace/mapper/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ def merge_default_values
end

def non_forced_defaults(default_vals)
default_vals.map { |field, val|
default_vals.map do |field, val|
origval = orig_data[field]
if origval.nil? || origval.empty?
[field, val]
end
}.compact.to_h
end.compact.to_h
end

def set_xpaths
Expand Down
4 changes: 2 additions & 2 deletions lib/collectionspace/mapper/term_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ def add_new_unknown_term(term_report)
CollectionSpace::Mapper::UsedTerm.new(**opts)
)
add_missing_record_error("term", val)
[val, case_swap(val)].each { |value|
[val, case_swap(val)].each do |value|
termcache.put("unknownvalue", type_subtype, value, urn)
}
end
end

# records the fact that this is an unknown term in the mapper response
Expand Down
4 changes: 2 additions & 2 deletions lib/collectionspace/mapper/xpaths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ def subgroups

def create_xpaths
mappings.group_by { |mapping| mapping.fullpath }
.map { |xpath, maps|
.map do |xpath, maps|
[xpath, CollectionSpace::Mapper::Xpath.new(
path: xpath,
mappings: maps,
handler: handler
)]
}.to_h
end.to_h
end

def set_subgroups
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
record: :new_episodes
}
context "with a missing term", vcr: vcr_opts do
let(:datahash_path) {
let(:datahash_path) do
"spec/support/datahashes/core/authorityHierarchy2.json"
}
end

it "sets response identifier" do
expect(response.identifier).to eq("Cats > Tuxedo cats")
Expand Down
4 changes: 2 additions & 2 deletions spec/collectionspace/mapper/batch_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
context "when initialized with Array" do
let(:configopt) { [2, 3] }
it "raises error" do
expect {
expect do
config
}.to raise_error(CollectionSpace::Mapper::UnhandledConfigFormatError)
end.to raise_error(CollectionSpace::Mapper::UnhandledConfigFormatError)
end
end

Expand Down
12 changes: 6 additions & 6 deletions spec/collectionspace/mapper/data_mapper_anthro_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
let(:mapper) { "anthro_4-1-2_claim" }

context "record 1" do
let(:datahash_path) {
let(:datahash_path) do
"spec/support/datahashes/anthro/claim1.json"
}
end
let(:fixture_path) { "anthro/claim1.xml" }

it_behaves_like "Mapped"
Expand All @@ -26,9 +26,9 @@
# Record 1 was used for testing default value merging, transformations,
# etc. We start with record 2 to purely test mapping functionality
context "record 2" do
let(:datahash_path) {
let(:datahash_path) do
"spec/support/datahashes/anthro/collectionobject2.json"
}
end
let(:fixture_path) { "anthro/collectionobject1.xml" }

it_behaves_like "Mapped"
Expand All @@ -39,9 +39,9 @@
let(:mapper) { "anthro_4-1-2_osteology" }

context "record 1" do
let(:datahash_path) {
let(:datahash_path) do
"spec/support/datahashes/anthro/osteology1.json"
}
end
let(:fixture_path) { "anthro/osteology1.xml" }

it_behaves_like "Mapped"
Expand Down
4 changes: 2 additions & 2 deletions spec/collectionspace/mapper/data_mapper_bonsai_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
let(:mapper) { "bonsai_4-1-1_objectexit" }

context "record 1" do
let(:datahash_path) {
let(:datahash_path) do
"spec/support/datahashes/bonsai/objectexit1.json"
}
end
let(:fixture_path) { "bonsai/objectexit1.xml" }

it_behaves_like "Mapped"
Expand Down
12 changes: 6 additions & 6 deletions spec/collectionspace/mapper/data_mapper_botgarden_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
let(:mapper) { "botgarden_3-0-2_pottag" }

context "record 1" do
let(:datahash_path) {
let(:datahash_path) do
"spec/support/datahashes/botgarden/pottag1.json"
}
end
let(:fixture_path) { "botgarden/pottag1.xml" }

it_behaves_like "Mapped"
Expand All @@ -24,9 +24,9 @@
let(:mapper) { "botgarden_3-0-2_propagation" }

context "record 1" do
let(:datahash_path) {
let(:datahash_path) do
"spec/support/datahashes/botgarden/propagation1.json"
}
end
let(:fixture_path) { "botgarden/propagation1.xml" }

# these tests are waiting for namespace uri fixes in CCU RecordMappers
Expand All @@ -40,9 +40,9 @@
let(:customcfg) { {response_mode: "verbose"} }

context "record 1" do
let(:datahash_path) {
let(:datahash_path) do
"spec/support/datahashes/botgarden/taxon1.json"
}
end
let(:fixture_path) { "botgarden/taxon_new.xml" }

it_behaves_like "Mapped"
Expand Down
Loading

0 comments on commit 2a2cc90

Please sign in to comment.