Skip to content

Commit

Permalink
rubocop fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
orangewolf committed Oct 1, 2023
1 parent 415c9ca commit 702627c
Show file tree
Hide file tree
Showing 16 changed files with 149 additions and 38 deletions.
81 changes: 81 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-10-01 05:24:49 +0000 using RuboCop version 0.52.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 25
Metrics/AbcSize:
Max: 63

# Offense count: 3
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 97

# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 102

# Offense count: 1
Metrics/CyclomaticComplexity:
Max: 7

# Offense count: 14
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 161

# Offense count: 24
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 33

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect.
Performance/HashEachMethods:
Exclude:
- 'app/controllers/catalog_controller_decorator.rb'

# Offense count: 3
RSpec/BeforeAfterAll:
Exclude:
- 'spec/spec_helper.rb'
- 'spec/rails_helper.rb'
- 'spec/support/**/*.rb'
- 'spec/models/hyku/group_spec.rb'
- 'spec/models/uploaded_file_spec.rb'

# Offense count: 31
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Enabled: false

# Offense count: 1
RSpec/ExpectInHook:
Exclude:
- 'spec/models/uploaded_file_spec.rb'

# Offense count: 2
RSpec/LetSetup:
Exclude:
- 'spec/models/role_spec.rb'
- 'spec/models/user_spec.rb'

# Offense count: 1
Rails/FilePath:
Exclude:
- 'spec/routing/**/*'
- 'lib/tasks/assets.rake'

# Offense count: 1
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'app/search_builders/adv_search_builder.rb'
9 changes: 6 additions & 3 deletions app/actors/hyrax/actors/collections_membership_actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@ def update(env)
# @param env [Hyrax::Actors::Enviornment]
# @return [Boolean]
#
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/PerceivedComplexity
# rubocop:disable Metrics/CyclomaticComplexity
def assign_nested_attributes_for_collection(env)
attributes_collection = env.attributes.delete(:member_of_collections_attributes)
return true unless attributes_collection

# OVERRIDE Hyrax 3.5.0 to skip permission checks if importing
# rubocop:disable Metrics/LineLength
return false unless env.importing ||
valid_membership?(env, collection_ids: attributes_collection.map { |_, attributes| attributes['id'] })
valid_membership?(env,
collection_ids: attributes_collection.map { |_, attributes| attributes['id'] })

# rubocop:enable Metrics/LineLength
attributes_collection = attributes_collection.sort_by { |i, _| i.to_i }.map { |_, attributes| attributes }
# checking for existing works to avoid rewriting/loading works that are already attached
existing_collections = env.curation_concern.member_of_collection_ids
Expand Down Expand Up @@ -120,7 +122,8 @@ def extract_collection_id(env)
end

def valid_membership?(env, collection_ids:)
multiple_memberships = Hyrax::MultipleMembershipChecker.new(item: env.curation_concern).check(collection_ids: collection_ids)
checker = Hyrax::MultipleMembershipChecker.new(item: env.curation_concern)
multiple_memberships = checker.check(collection_ids: collection_ids)
if multiple_memberships
env.curation_concern.errors.add(:collections, multiple_memberships)
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def attach!
# Escape any space characters, so that this is a legal URI
uri = URI.parse(Addressable::URI.escape(file_info[:url]))
unless self.class.validate_remote_url(uri)
Rails.logger.error "User #{user.user_key} attempted to ingest file from url #{file_info[:url]}, which doesn't pass validation"
msg = "User #{user.user_key} attempted to ingest file from url #{file_info[:url]}"
msg += ", which doesn't pass validation"
Rails.logger.error msg
return false
end
auth_header = file_info.fetch(:auth_header, {})
Expand All @@ -35,7 +37,9 @@ def create_file_from_url(uri, file_name, auth_header, override_default_thumbnail
use_valkyrie = true
else
# OVERRIDE Hyrax 3.5 to override default_thumbnail
file_set = ::FileSet.new(import_url: import_url, label: file_name, override_default_thumbnail: override_default_thumbnail)
file_set = ::FileSet.new(import_url: import_url,
label: file_name,
override_default_thumbnail: override_default_thumbnail)
end
__create_file_from_url(file_set: file_set, uri: uri, auth_header: auth_header, use_valkyrie: use_valkyrie)
end
Expand All @@ -44,4 +48,6 @@ def create_file_from_url(uri, file_name, auth_header, override_default_thumbnail
end
end

# rubocop:disable Metrics/LineLength
Hyrax::Actors::CreateWithRemoteFilesActor::IngestRemoteFilesService.prepend Hyrax::Actors::CreateWithRemoteFilesActorDecorator::IngestRemoteFilesServiceDecorator
# rubocop:enable Metrics/LineLength
15 changes: 11 additions & 4 deletions app/actors/hyrax/actors/file_set_actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Hyrax
module Actors
# Actions are decoupled from controller logic so that they may be called from a controller or a background job.
class FileSetActor
class FileSetActor # rubocop:disable Metrics/ClassLength
include Lockable
attr_reader :file_set, :user, :attributes

Expand Down Expand Up @@ -54,7 +54,8 @@ def update_content(file, relation = :original_file)
# Adds the appropriate metadata, visibility and relationships to file_set
# @note In past versions of Hyrax this method did not perform a save because it is mainly used in conjunction with
# create_content, which also performs a save. However, due to the relationship between Hydra::PCDM objects,
# we have to save both the parent work and the file_set in order to record the "metadata" relationship between them.
# we have to save both the parent work and the file_set in order to record the "metadata" relationship
# between them.
# @param [Hash] file_set_params specifying the visibility, lease and/or embargo of the file set.
# Without visibility, embargo_release_date or lease_expiration_date, visibility will be copied from the parent.
def create_metadata(file_set_params = {})
Expand Down Expand Up @@ -154,7 +155,8 @@ def assign_visibility?(file_set_params = {})
!((file_set_params || {}).keys.map(&:to_s) & %w[visibility embargo_release_date lease_expiration_date]).empty?
end

# replaces file_set.apply_depositor_metadata(user)from hydra-access-controls so depositor doesn't automatically get edit access
# replaces file_set.apply_depositor_metadata(user)from hydra-access-controls so depositor doesn't
# automatically get edit access
def depositor_id(depositor)
depositor.respond_to?(:user_key) ? depositor.user_key : depositor
end
Expand All @@ -164,7 +166,12 @@ def depositor_id(depositor)
# Although ActiveFedora clears the children nodes it leaves those fields in Solr populated.
def unlink_from_work
work = file_set.parent
return unless work && (work.thumbnail_id == file_set.id || work.representative_id == file_set.id || work.rendering_ids.include?(file_set.id))
return unless work &&
(
work.thumbnail_id == file_set.id ||
work.representative_id == file_set.id ||
work.rendering_ids.include?(file_set.id)
)
work.thumbnail = nil if work.thumbnail_id == file_set.id
work.representative = nil if work.representative_id == file_set.id
work.rendering_ids -= [file_set.id]
Expand Down
10 changes: 6 additions & 4 deletions app/controllers/catalog_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

CatalogController.include DogBiscuits::Blacklight::Commands

# rubocop:disable Metrics/BlockLength
CatalogController.configure_blacklight do |config|
# Use locally customized AdvSearchBuilder so we can enable blacklight_advanced_search
config.search_builder_class = AdvSearchBuilder
Expand Down Expand Up @@ -36,7 +34,8 @@
config.add_facet_field 'part_of_sim', limit: 5
config.add_facet_field 'refereed_sim', limit: 5

# Prior to this change, the applications specific translations were not loaded. Dogbiscuits were assuming the translations were already loaded.
# Prior to this change, the applications specific translations were not loaded.
# Dogbiscuits were assuming the translations were already loaded.
Rails.root.glob("config/locales/*.yml").each do |path|
I18n.load_path << path.to_s
end
Expand All @@ -57,7 +56,10 @@
CatalogController.send(:add_index_field, config, index_props)

config.search_fields.delete('all_fields')
config.add_search_field('all_fields', label: 'All Fields', include_in_advanced_search: false, advanced_parse: false) do |field|
config.add_search_field('all_fields',
label: 'All Fields',
include_in_advanced_search: false,
advanced_parse: false) do |field|
all_names = (config.show_fields.values.map { |v| v.field.to_s } +
DogBiscuits.config.all_properties.map { |p| "#{p}_tesim" }).uniq.join(" ")
title_name = 'title_tesim'
Expand Down
1 change: 0 additions & 1 deletion app/indexers/app_indexer_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

module AppIndexerDecorator
# rubocop:disable Metrics/AbcSize
def generate_solr_document
super.tap do |solr_doc|
solr_doc["account_cname_tesim"] = Site.instance&.account&.cname
Expand Down
1 change: 0 additions & 1 deletion app/jobs/index_plain_text_files_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class IndexPlainTextFilesJob < ApplicationJob
# @see https://docs.ruby-lang.org/en/2.7.0/String.html#method-i-encode
class One < ApplicationJob
# @param file_set_id [String]
# rubocop:disable Metrics/BlockLength
def perform(account, file_set_id, time_to_live = 3, logger: IndexPlainTextFilesJob.default_logger)
account.switch do
begin
Expand Down
9 changes: 8 additions & 1 deletion app/matchers/bulkrax/application_matcher_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ module ApplicationMatcherDecorator
# OVERRIDE Bulkrax 1.0.2 to override default_thumbnail
def process_parse
# New parse methods will need to be added here
parsed_fields = ['remote_files', 'language', 'subject', 'types', 'model', 'resource_type', 'format_original', 'thumbnail_url']
parsed_fields = ['remote_files',
'language',
'subject',
'types',
'model',
'resource_type',
'format_original',
'thumbnail_url']
# This accounts for prefixed matchers
parser = parsed_fields.find { |field| to&.include? field }

Expand Down
8 changes: 7 additions & 1 deletion app/presenters/hyrax/image_presenter_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# frozen_string_literal: true

Hyrax::ImagePresenter.delegate :aark_id, :abstract, :date_issued, :alt, :part_of, :place_of_publication, :remote_url, to: :solr_document
Hyrax::ImagePresenter.delegate :aark_id,
:abstract,
:date_issued,
:alt,
:part_of,
:place_of_publication,
:remote_url, to: :solr_document
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

# OVERRIDE IiifPrint v1.0.0 to not render thumbnail files in the UV

# rubocop:disable Metrics/BlockLength
IiifPrint::ManifestBuilderServiceBehavior.module_eval do
def build_manifest(presenter:)
manifest = manifest_factory.new(presenter).to_h
Expand Down
4 changes: 2 additions & 2 deletions lib/hyku_knapsack/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class Engine < ::Rails::Engine
my_engine_root = HykuKnapsack::Engine.root.to_s

# need collection model first
c = "#{my_engine_root}/app/models/collection_decorator.rb"
Rails.configuration.cache_classes ? require(c) : load(c)
code = "#{my_engine_root}/app/models/collection_decorator.rb"
Rails.configuration.cache_classes ? require(code) : load(code)

Dir.glob(File.join(my_engine_root, "app/**/*_decorator*.rb")).sort.each do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/assets.rake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace :hyku_knapsack do
Dir.glob(File.join(HykuKnapsack::Engine.root, 'public', '**')).each do |asset|
# skip directories
next unless File.file?(asset)
dest_file = File.join(Rails.root, 'public', File.basename(asset))
dest_file = Rails.root.join('public', File.basename(asset))
FileUtils.copy_file source_file, dest_file, true
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/features/facet_by_year_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@
end

it "displays plot after facet is expanded" do
# rubocop:disable Metrics/LineLength
visit "/catalog/range_limit?commit=Limit&locale=en&q=&range_end=2021&range_field=sorted_year_isi&range_start=2&search_field=all_fields"
# rubocop:enable Metrics/LineLength
expect(page.status_code).to eq 200
end
end
6 changes: 3 additions & 3 deletions spec/presenters/hyku/admin/group/navigation_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
end

context 'edit page' do
context 'with edit page' do
subject { presenter.tabs }

let(:action) { 'edit' }
Expand All @@ -25,7 +25,7 @@
end
end

context 'members page' do
context 'with members page' do
subject { presenter.tabs }

let(:action) { 'index' }
Expand All @@ -41,7 +41,7 @@
end
end

context 'remve page' do
context 'with remve page' do
subject { presenter.tabs }

let(:action) { 'remove' }
Expand Down
Loading

0 comments on commit 702627c

Please sign in to comment.