Skip to content

Commit

Permalink
💄 replaces deprecated rubocop statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Shana Moore committed Aug 15, 2024
1 parent e33b424 commit d2957c9
Show file tree
Hide file tree
Showing 22 changed files with 155 additions and 222 deletions.
43 changes: 42 additions & 1 deletion .rubocop_fixme.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@
# This configuration was generated by
# `rubocop --auto-gen-config --exclude-limit 0`
# on 2024-08-14 22:12:29 UTC using RuboCop version 1.61.0.
# on 2024-08-15 14:53:42 UTC using RuboCop version 1.61.0.
# 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: 3
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
Layout/ExtraSpacing:
Enabled: false

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowForAlignment.
Layout/SpaceBeforeFirstArg:
Enabled: false

# Offense count: 1
# Configuration parameters: AllowedParentClasses.
Lint/MissingSuper:
Enabled: false

# Offense count: 8
# Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Enabled: false

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
# SupportedShorthandSyntax: always, never, either, consistent
Style/HashSyntax:
Enabled: false

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantParentheses:
Enabled: false

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowMultipleReturnValues.
Style/RedundantReturn:
Enabled: false
69 changes: 1 addition & 68 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,74 +1,7 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-08-14 22:12:52 UTC using RuboCop version 1.61.0.
# on 2024-08-15 14:54:14 UTC using RuboCop version 1.61.0.
# 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: 3
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
Layout/ExtraSpacing:
Exclude:
- 'spec/models/account_spec.rb'

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowForAlignment.
Layout/SpaceBeforeFirstArg:
Exclude:
- 'spec/models/account_spec.rb'

# Offense count: 7
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowInHeredoc.
Layout/TrailingWhitespace:
Exclude:
- 'app/models/sushi/item_report.rb'
- 'app/models/sushi/platform_report.rb'

# Offense count: 1
# Configuration parameters: AllowedParentClasses.
Lint/MissingSuper:
Exclude:
- 'spec/services/iiif_print/tenant_config_spec.rb'

# Offense count: 12
# Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Exclude:
- 'app/controllers/application_controller.rb'
- 'app/controllers/hyrax/dashboard/collections_controller_decorator.rb'
- 'app/controllers/identity_providers_controller.rb'
- 'app/controllers/users/omniauth_callbacks_controller.rb'
- 'app/helpers/blacklight/catalog_helper_behavior_decorator.rb'
- 'app/jobs/batch_email_notification_job.rb'
- 'app/jobs/reindex_works_job.rb'
- 'app/models/sort_title.rb'
- 'app/models/sushi.rb'
- 'lib/reprocessor.rb'

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
# SupportedShorthandSyntax: always, never, either, consistent
Style/HashSyntax:
Exclude:
- 'app/controllers/roles_controller.rb'
- 'spec/views/hyrax/base/_relationships.html.erb_spec.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantParentheses:
Exclude:
- 'app/models/hydra/access_controls/embargo_decorator.rb'
- 'app/models/hydra/access_controls/lease_decorator.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowMultipleReturnValues.
Style/RedundantReturn:
Exclude:
- 'app/helpers/application_helper.rb'
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ gem 'willow_sword', github: 'scientist-softserv/willow_sword', branch: 'main'
# of the time use the `samvera-labs/hyku_knapsack` remote branch.
gem 'hyku_knapsack', github: 'samvera-labs/hyku_knapsack', branch: 'required_for_knapsack_instances'

# rubocop:enable Layout/LineLength
# rubocop:enable Metrics/MethodLength
4 changes: 3 additions & 1 deletion app/helpers/blacklight/catalog_helper_behavior_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# OVERRIDE blacklight 6 to allow full url for show links for shared search thumbnail
module Blacklight
module CatalogHelperBehaviorDecorator
# rubocop:disable Metrics/MethodLength
def render_thumbnail_tag(document, image_options = {}, url_options = {})
value = if blacklight_config.view_config(document_index_view_type).thumbnail_method
send(blacklight_config.view_config(document_index_view_type).thumbnail_method, document, image_options)
Expand All @@ -15,7 +16,7 @@ def render_thumbnail_tag(document, image_options = {}, url_options = {})
if value
if url_options == false
Deprecation.warn(self, "passing false as the second argument to render_thumbnail_tag is deprecated. Use suppress_link: true instead. This behavior will be removed in Blacklight 7")
# rubocop:enable Layout/LineLength
# rubocop:enable Metrics/MethodLength
url_options = { suppress_link: true }
end
if url_options[:suppress_link]
Expand All @@ -30,6 +31,7 @@ def render_thumbnail_tag(document, image_options = {}, url_options = {})
end
# rubocop:enable Style/GuardClause
end
# rubocop:enable Metrics/MethodLength
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/pdf_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module PdfBehavior
property :show_pdf_download_button, predicate: RDF::CustomShowPdfDownloadButtonTerm.show_pdf_download_button, multiple: false do |index|
index.as :stored_searchable
end
# rubocop:enable Layout/LineLength
# rubocop:enable Metrics/MethodLength

after_initialize :set_default_show_pdf_viewer, :set_default_show_pdf_download_button
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/featured_collection_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def featured_collections_attributes=(attributes_collection)
existing_record = FeaturedCollection.find(attributes['id'])
existing_record.update(attributes.except('id'))
end
# rubocop:enable Layout/LineLength
# rubocop:enable Metrics/MethodLength
end

def featured_collections
Expand Down
16 changes: 10 additions & 6 deletions app/models/sushi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def validate_date_format(dates = [])

# rubocop:disable Layout/LineLength
info << Sushi::Info.new(data: date.to_s, message: "The day of the month is not taken into consideration when providing metrics. The date provided was amended to account for the full month.").as_json if match[2]
# rubocop:enable Layout/LineLength
# rubocop:enable Metrics/MethodLength
end

true
Expand Down Expand Up @@ -195,14 +195,14 @@ def coerce_dates(params = {})
if @begin_date < earliest_date
# rubocop:disable Layout/LineLength
raise Sushi::Error::UsageNoLongerAvailableForRequestedDatesError.new(data: "Unable to complete the request because the begin_date of #{params[:begin_date]} is for a month that has incomplete data. That month's data starts on #{earliest_date.iso8601}.")
# rubocop:enable Layout/LineLength
# rubocop:enable Metrics/MethodLength
end

latest_date = Hyrax::CounterMetric.order(date: :desc).first.date
if @end_date > latest_date
# rubocop:disable Layout/LineLength
raise Sushi::Error::UsageNotReadyForRequestedDatesError.new(data: "Unable to complete the request because the end_date of #{params[:end_date]} is for a month that has incomplete data. That month's data ends on #{latest_date.iso8601}.")
# rubocop:enable Layout/LineLength
# rubocop:enable Metrics/MethodLength
end
rescue ActionController::ParameterMissing, KeyError => e
raise Sushi::Error::InsufficientInformationToProcessRequestError.new(data: e.message)
Expand Down Expand Up @@ -234,6 +234,7 @@ module MetricTypeCoercion
attr_reader :metric_types, :metric_type_in_params
end

# rubocop:disable Metrics/MethodLength
def coerce_metric_types(params = {}, allowed_types: ALLOWED_METRIC_TYPES)
metric_types_from_params = Array.wrap(params[:metric_type]&.split('|'))
return @metric_types = allowed_types if metric_types_from_params.empty?
Expand All @@ -256,6 +257,7 @@ def coerce_metric_types(params = {}, allowed_types: ALLOWED_METRIC_TYPES)
metric_type.titleize.tr(' ', '_') if allowed_types.any? { |allowed_type| allowed_type.downcase == normalized_metric_type }
end.compact
end
# rubocop:enable Metrics/MethodLength
end

module AccessMethodCoercion
Expand Down Expand Up @@ -304,7 +306,7 @@ def coerce_item_id(params = {})

# rubocop:disable Layout/LineLength
raise Sushi::Error::InvalidReportFilterValueError.new(data: "The given parameter `item_id=#{params[:item_id]}` does not exist. Please provide an existing item_id, or none at all.") unless Hyrax::CounterMetric.exists?(work_id: params[:item_id])
# rubocop:enable Layout/LineLength
# rubocop:enable Metrics/MethodLength

@item_id = params[:item_id]
@item_id_in_params = true
Expand Down Expand Up @@ -421,7 +423,7 @@ def coerce_author(params = {})

# rubocop:disable Layout/LineLength
raise Sushi::Error::InvalidReportFilterValueError.new(data: "The given author #{author.inspect} was not found in the metrics.") unless Hyrax::CounterMetric.where(author_as_where_parameters).exists?
# rubocop:enable Layout/LineLength
# rubocop:enable Metrics/MethodLength

@author_in_params = true
end
Expand Down Expand Up @@ -465,6 +467,7 @@ module YearOfPublicationCoercion
# @note No special consideration is made for date ranges that start with a later date and end with
# an earlier date (e.g. "1999-1994" will be "date >= 1999 AND date <= 1994"; which will
# return no entries.)
# rubocop:disable Metrics/MethodLength
def coerce_yop(params = {})
return unless params.key?(:yop)

Expand All @@ -491,7 +494,8 @@ def coerce_yop(params = {})
rescue ArgumentError
# rubocop:disable Layout/LineLength
raise Sushi::Error::InvalidDateArgumentError.new(data: "The given parameter `yop=#{yop}` was malformed. You can provide a range (e.g. 'YYYY-YYYY') or a single date (e.g. 'YYYY'). You can separate ranges/values with a '|'.")
# rubocop:enable Layout/LineLength
# rubocop:enable Metrics/MethodLength
end
# rubocop: Metrics/MethodLength
end
end
52 changes: 18 additions & 34 deletions app/models/sushi/item_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,30 @@ def as_json(_options = {})

alias to_hash as_json

# rubocop:disable Metrics/MethodLength
def report_items
data_for_resource_types.map do |record|
{
'Items' => [item_attributes(record)]
'Items' => [{
'Attribute_Performance' => [{
'Data_Type' => record.resource_type.titleize,
# We are only supporting the 'Regular' access method at this time. If that changes, we will need to update this.
'Access_Method' => 'Regular',
'Performance' => performance(record)
}],
'Authors' => Sushi::AuthorCoercion.deserialize(record.author).map { |author| { 'Name:' => author } },
'Item' => record.work_id.to_s,
'Publisher' => '',
'Platform' => account.cname,
'Item_ID' => {
'Proprietary': record.work_id.to_s,
'URI': "https://#{account.cname}/concern/#{record.worktype.underscore}s/#{record.work_id}"
}
}]
}
end
end
# rubocop:enable Metrics/MethodLength

def performance(record)
metric_types.index_with do |metric_type|
Expand Down Expand Up @@ -169,39 +186,6 @@ def data_for_resource_types
relation
end
# rubocop:enable Metrics/MethodLength

private

def item_attributes(record)
{
'Attribute_Performance' => attribute_performance(record),
'Authors' => authors(record),
'Item' => record.work_id.to_s,
'Publisher' => '',
'Platform' => account.cname,
'Item_ID' => item_id(record)
}
end

def attribute_performance(record)
[{
'Data_Type' => record.resource_type.titleize,
# We are only supporting the 'Regular' access method at this time. If that changes, we will need to update this.
'Access_Method' => 'Regular',
'Performance' => performance(record)
}]
end

def authors(record)
Sushi::AuthorCoercion.deserialize(record.author).map { |author| { 'Name:' => author } }
end

def item_id(record)
{
'Proprietary': record.work_id.to_s,
'URI': "https://#{account.cname}/concern/#{record.worktype.underscore}s/#{record.work_id}"
}
end
end
# rubocop:enable Metrics/ClassLength
end
Loading

0 comments on commit d2957c9

Please sign in to comment.