Skip to content

Commit

Permalink
Upgrade rubocop and autocorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Nov 3, 2023
1 parent 42ddfdb commit 1776260
Show file tree
Hide file tree
Showing 30 changed files with 101 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require:
- rubocop-performance

AllCops:
TargetRubyVersion: 2.5
TargetRubyVersion: 3.1
DisplayCopNames: true
Exclude:
- 'Gemfile'
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ group :development, :test do
gem 'webdrivers'

# Rubocop is a static code analyzer to enforce style.
gem 'rubocop', '~> 0.50', require: false
gem 'rubocop', '~> 1.57', require: false
gem 'rubocop-performance', require: false
gem 'rubocop-rails', require: false
gem 'rubocop-rspec', require: false
Expand Down
33 changes: 21 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ GEM
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
json (2.6.3)
jwt (2.7.1)
language_server-protocol (3.17.0.3)
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
Expand Down Expand Up @@ -255,7 +257,7 @@ GEM
public_suffix (5.0.3)
puma (5.6.7)
nio4r (~> 2.0)
racc (1.7.1)
racc (1.7.2)
rack (2.2.8)
rack-test (2.1.0)
rack (>= 1.3)
Expand Down Expand Up @@ -324,27 +326,34 @@ GEM
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.12.1)
rubocop (0.93.1)
rubocop (1.57.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 2.7.1.5)
parser (>= 3.2.2.4)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8)
rexml
rubocop-ast (>= 0.6.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.19.0)
rubocop (~> 1.41)
rubocop-factory_bot (2.24.0)
rubocop (~> 1.33)
rubocop-performance (1.10.2)
rubocop (>= 0.90.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.9.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 0.90.0, < 2.0)
rubocop-rspec (1.44.1)
rubocop (~> 0.87)
rubocop-ast (>= 0.7.1)
rubocop-rspec (2.25.0)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
Expand All @@ -371,7 +380,7 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.8.2)
unicode-display_width (1.8.0)
unicode-display_width (2.5.0)
web-console (4.2.1)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
Expand Down Expand Up @@ -435,7 +444,7 @@ DEPENDENCIES
redis
retries
rspec-rails (~> 5.0)
rubocop (~> 0.50)
rubocop (~> 1.57)
rubocop-performance
rubocop-rails
rubocop-rspec
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/cdl_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ def show_options
# - exp (due date)
# - barcode (note: the actual item barcode may differ from the one in the SDR item)
def create
render json: 'invalid barcode', status: 400 and return unless barcode
render json: 'invalid barcode', status: :bad_request and return unless barcode

checkout_params = {
id: params[:id],
barcode: barcode,
barcode:,
modal: true,
return_to: cdl_checkout_success_iiif_auth_api_url(params[:id])
}
Expand All @@ -66,12 +66,12 @@ def create_success
def delete
token = existing_payload[:token]

checkin_params = { token: token, return_to: cdl_checkin_success_iiif_auth_api_url(params[:id]) }
checkin_params = { token:, return_to: cdl_checkin_success_iiif_auth_api_url(params[:id]) }
redirect_to "#{Settings.cdl.url}/checkin?#{checkin_params.to_param}"
end

def delete_success
# Note: the user may have lost its token already (because it was marked as expired)
# NOTE: the user may have lost its token already (because it was marked as expired)
bad_tokens, good_tokens = current_user.cdl_tokens.partition { |payload| payload['aud'] == params[:id] }
cookies.encrypted[:tokens] = good_tokens.pluck(:token) if bad_tokens.any?

Expand All @@ -84,7 +84,7 @@ def delete_success
def renew
token = existing_payload[:token]

renew_params = { modal: true, token: token, return_to: cdl_renew_success_iiif_auth_api_url(params[:id]) }
renew_params = { modal: true, token:, return_to: cdl_renew_success_iiif_auth_api_url(params[:id]) }
redirect_to "#{Settings.cdl.url}/renew?#{renew_params.to_param}"
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/current_user_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def webauth_user
User.new(id: session[:remote_user] || request.remote_user,
ip_address: request.remote_ip,
webauth_user: true,
ldap_groups: ldap_groups,
ldap_groups:,
jwt_tokens: cookies.encrypted[:tokens]).tap { |user| clean_up_expired_cdl_tokens(user) }
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/file_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def show
response.headers['Content-Length'] = current_file.content_length
response.headers.delete('X-Frame-Options')

send_file current_file.path, disposition: disposition
send_file current_file.path, disposition:
end

def options
Expand Down
14 changes: 6 additions & 8 deletions app/controllers/iiif_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ def show
# IIIF info.json endpoint
# rubocop:disable Metrics/PerceivedComplexity
def metadata
unless Rails.env.development?
raise ActionController::MissingFile, 'File Not Found' unless current_image.exist?
end
raise ActionController::MissingFile, 'File Not Found' if !Rails.env.development? && !current_image.exist?

return unless stale?(**cache_headers_metadata)

Expand All @@ -55,7 +53,7 @@ def metadata

respond_to do |format|
format.any(:json, :jsonld) do
render json: image_info, status: status
render json: image_info, status:
end
end
end
Expand Down Expand Up @@ -126,16 +124,16 @@ def set_attachment_content_disposition_header

def current_image
@image ||= begin
img = StacksImage.new(stacks_image_params)
can?(:download, img) ? img : img.restricted
end
img = StacksImage.new(stacks_image_params)
can?(:download, img) ? img : img.restricted
end
end

def identifier_params
return params.permit(:id, :file_name).to_h if params[:id] && params[:file_name]

id, file_name = params[:identifier].sub('/', '%2F').split('%2F', 2)
{ id: id, file_name: file_name }
{ id:, file_name: }
end

def stacks_image_params
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/iiif_token_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def create_for_json_access_token_auth(token)
:unauthorized
end

render json: @message.to_json, callback: callback_value, status: status
render json: @message.to_json, callback: callback_value, status:
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/legacy_image_service_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def show
def iiif_options
@image.transformation
.to_params
.merge(id: id, file_name: file_name,
.merge(id:, file_name:,
download: allowed_params[:download])
end

Expand Down Expand Up @@ -86,7 +86,7 @@ def iiif_region
end

def identifier_params
{ id: id, file_name: file_name }
{ id:, file_name: }
end

def id
Expand Down
4 changes: 2 additions & 2 deletions app/models/iiif_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ def response
private

def image_uri
@image_uri ||= IIIF::Image::URI.new(base_uri: @base_uri, identifier: remote_id, transformation: transformation)
@image_uri ||= IIIF::Image::URI.new(base_uri: @base_uri, identifier: remote_id, transformation:)
end

def image_url
image_uri.to_s
end

def remote_id
CGI.escape(StacksFile.new(id: id, file_name: file_name).treeified_path)
CGI.escape(StacksFile.new(id:, file_name:).treeified_path)
end

attr_reader :transformation, :id, :file_name
Expand Down
4 changes: 2 additions & 2 deletions app/models/projection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def explicit_tile_dimensions(requested_size)
else
requested_size.width
end
IIIF::Image::Dimension.new(width: width, height: height)
IIIF::Image::Dimension.new(width:, height:)
end

def absolute_region?
Expand Down Expand Up @@ -108,7 +108,7 @@ def square_region_dimensions

# @return [IiifImage]
def image_source
@image_source ||= IiifImage.new(id: id, file_name: file_name, transformation: real_transformation)
@image_source ||= IiifImage.new(id:, file_name:, transformation: real_transformation)
end

def real_transformation
Expand Down
6 changes: 2 additions & 4 deletions app/models/stacks_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@ def treeified_path
end

def druid_parts
@druid_parts ||= begin
id.match(/^([a-z]{2})(\d{3})([a-z]{2})(\d{4})$/i)
end
@druid_parts ||= id.match(/^([a-z]{2})(\d{3})([a-z]{2})(\d{4})$/i)
end

def stacks_rights
@stacks_rights ||= StacksRights.new(id: id, file_name: file_name)
@stacks_rights ||= StacksRights.new(id:, file_name:)
end
delegate :rights, to: :stacks_rights
end
14 changes: 7 additions & 7 deletions app/models/stacks_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class StacksImage

# @return [RestrictedImage] the restricted version of this image
def restricted
RestrictedImage.new(transformation: transformation,
id: id,
file_name: file_name,
canonical_url: canonical_url)
RestrictedImage.new(transformation:,
id:,
file_name:,
canonical_url:)
end

# @return [Hash]
Expand Down Expand Up @@ -51,16 +51,16 @@ def projection_for(transformation)

# @return [StacksFile]
def file_source
@file_source ||= StacksFile.new(id: id, file_name: file_name)
@file_source ||= StacksFile.new(id:, file_name:)
end

# @return [InfoService]
def info_service
@info_service ||= IiifMetadataService.new(id: id, file_name: file_name, canonical_url: canonical_url)
@info_service ||= IiifMetadataService.new(id:, file_name:, canonical_url:)
end

def stacks_rights
@stacks_rights ||= StacksRights.new(id: id, file_name: file_name)
@stacks_rights ||= StacksRights.new(id:, file_name:)
end
delegate :rights, :maybe_downloadable?, :object_thumbnail?,
:stanford_restricted?, :restricted_by_location?, :cdl_restricted?, to: :stacks_rights
Expand Down
4 changes: 2 additions & 2 deletions app/models/stacks_media_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ class StacksMediaStream

# @return [StacksFile] the file on disk that back this projection
def file
@file ||= StacksFile.new(id: id, file_name: file_name)
@file ||= StacksFile.new(id:, file_name:)
end

attr_accessor :format, :id, :file_name

delegate :etag, :mtime, to: :file

def stacks_rights
@stacks_rights ||= StacksRights.new(id: id, file_name: file_name)
@stacks_rights ||= StacksRights.new(id:, file_name:)
end
delegate :rights, :restricted_by_location?, :stanford_restricted?, to: :stacks_rights
end
8 changes: 4 additions & 4 deletions app/models/stacks_media_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ def initialize(id, file_name, user_ip)

def to_hash
{
id: id,
file_name: file_name,
user_ip: user_ip,
timestamp: timestamp
id:,
file_name:,
user_ip:,
timestamp:
}
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def decode_token(token)
payload, headers = JWT.decode(token, Settings.cdl.jwt.secret, true, {
algorithm: Settings.cdl.jwt.algorithm, sub: id, verify_sub: true
})
[payload&.merge(token: token)&.with_indifferent_access, headers]
[payload&.merge(token:)&.with_indifferent_access, headers]
rescue JWT::ExpiredSignature, JWT::InvalidSubError
nil
end
Expand Down Expand Up @@ -105,7 +105,7 @@ def token
self.class.encryptor.encrypt_and_sign(
[
# stored parameters
{ id: id, ldap_groups: ldap_groups, ip_address: ip_address, jwt_tokens: jwt_tokens },
{ id:, ldap_groups:, ip_address:, jwt_tokens: },
# mint time
mint_time,
# expiry time
Expand Down
12 changes: 5 additions & 7 deletions app/services/iiif_metadata_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class IiifMetadataService
# @param canonical_url [String]
# @param base_uri [String] base path to the IIIF server
def initialize(id:, file_name:, canonical_url:, base_uri: Settings.imageserver.base_uri)
identifier = CGI.escape(StacksFile.new(id: id, file_name: file_name).treeified_path)
@url = IIIF::Image::URI.new(identifier: identifier, base_uri: base_uri).to_s
identifier = CGI.escape(StacksFile.new(id:, file_name:).treeified_path)
@url = IIIF::Image::URI.new(identifier:, base_uri:).to_s
@canonical_url = canonical_url
end

Expand Down Expand Up @@ -68,11 +68,9 @@ def handle_response(conn)

def json
retrieved_json = retrieve
@json ||= begin
JSON.parse(retrieved_json).tap do |data|
data['@id'] = @canonical_url
end
end
@json ||= JSON.parse(retrieved_json).tap do |data|
data['@id'] = @canonical_url
end
rescue JSON::ParserError => e
raise Stacks::UnexpectedMetadataResponseError, "There was a problem fetching #{@url}. #{e}: #{retrieved_json}"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/abilities/ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@

describe 'for an object with CDL rights' do
let(:user) do
User.new(id: 'a', webauth_user: true, ldap_groups: %w(stanford:stanford), jwt_tokens: jwt_tokens)
User.new(id: 'a', webauth_user: true, ldap_groups: %w(stanford:stanford), jwt_tokens:)
end
let(:jwt_tokens) { [] }
let(:rights_xml) do
Expand Down
Loading

0 comments on commit 1776260

Please sign in to comment.