Skip to content

Commit

Permalink
Merge pull request #295 from sosol/rubocop-autocorrect
Browse files Browse the repository at this point in the history
Rubocop autocorrect
  • Loading branch information
ryanfb authored Jan 28, 2022
2 parents 082154e + 0e7dceb commit cc0c5e8
Show file tree
Hide file tree
Showing 262 changed files with 11,482 additions and 11,555 deletions.
21 changes: 21 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require:
- rubocop-minitest
- rubocop-performance
- rubocop-rails
- rubocop-rake

Performance/ConstantRegexp:
Enabled: false

Performance/StringInclude:
Exclude:
- 'app/helpers/hgv_meta_identifier_helper.rb'

AllCops:
NewCops: enable

Style/FrozenStringLiteralComment:
Enabled: false

Rails/ApplicationMailer:
Enabled: false
78 changes: 43 additions & 35 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,60 +1,68 @@
# Edit this Gemfile to bundle your application's dependencies.
# This preamble is the current preamble for Rails 3 apps; edit as needed.
source 'https://rubygems.org'
ruby "2.5.8", :engine => "jruby", :engine_version => "9.2.20.1"
ruby '2.5.8', engine: 'jruby', engine_version: '9.2.20.1'

gem 'rails', '~> 6.1.4.4'

# Needed for the new asset pipeline
gem 'sass-rails', '~> 5'
gem 'coffee-rails'
gem 'uglifier', '>= 1.0.3'
gem 'sass-rails', '~> 5'
gem 'therubyrhino'
gem 'uglifier', '>= 1.0.3'

group :test do
gem 'rake'
gem 'database_cleaner-active_record'
gem 'factory_bot_rails'
gem 'mocha'
gem 'rails-controller-testing'
gem 'rake'
gem 'shoulda'
gem 'shoulda-context'
gem 'shoulda-matchers'
gem 'shoulda'
gem 'factory_bot_rails'
gem 'database_cleaner-active_record'
gem 'rails-controller-testing'
end

gem 'jquery-rails'
gem 'jruby-jars', File.read('.ruby-version').chomp.sub(/^jruby-/,'')
group :development, :test do
gem 'rubocop'
gem 'rubocop-minitest'
gem 'rubocop-performance'
gem 'rubocop-rails'
gem 'rubocop-rake'
end

gem 'haml-rails', '~> 2.0'
gem 'jquery-rails'
gem 'jruby-jars', File.read('.ruby-version').chomp.sub(/^jruby-/, '')
gem 'sass'
# gem 'json-jruby', '>= 1.6.6', :require => 'json', :platform => :jruby
gem 'json', '>=1.6.6'
gem 'jdbc-sqlite3', '>= 3.7.2', :platform => :jruby
gem 'activerecord-jdbc-adapter', '>= 1.3.25', '~> 61', :platform => :jruby
gem 'activerecord-jdbcsqlite3-adapter', '>= 1.3.25', '~> 61', :platform => :jruby
gem 'activerecord-jdbcmysql-adapter', '>= 1.3.25', '~> 61', :platform => :jruby
gem 'activerecord-jdbcpostgresql-adapter', '>= 1.3.25', '~> 61', :platform => :jruby
gem 'jdbc-mysql', require: false
gem 'activerecord-session_store'
gem 'tzinfo-data', :platform => :jruby
gem 'actionpack-page_caching'
gem 'rack', '>= 1.1.0'
gem 'handle_invalid_percent_encoding_requests'
gem 'activerecord-jdbc-adapter', '>= 1.3.25', '~> 61', platform: :jruby
gem 'activerecord-jdbcmysql-adapter', '>= 1.3.25', '~> 61', platform: :jruby
gem 'activerecord-jdbcpostgresql-adapter', '>= 1.3.25', '~> 61', platform: :jruby
gem 'activerecord-jdbcsqlite3-adapter', '>= 1.3.25', '~> 61', platform: :jruby
gem 'activerecord-session_store'
gem 'airbrake'
gem 'rubyzip', '~> 1.0'
gem 'zip-zip'
gem 'dynamic_form'
gem 'capistrano', '~> 2.15.0'
gem 'warbler', '~> 2.0'
gem 'puma'
gem 'sucker_punch', '~> 2.0'
gem 'with_advisory_lock'
gem 'silencer'
gem 'rack-attack', '~> 4.0'
gem 'i18n'
gem "pry", "~> 0.14.0"
gem "pry-rails", "~> 0.3.9"
gem 'devise', '~> 4.8'
gem 'omniauth-google-oauth2'
gem 'dotenv-rails'
gem 'omniauth-rails_csrf_protection'
gem 'dynamic_form'
gem 'handle_invalid_percent_encoding_requests'
gem 'httpclient'
gem 'i18n'
gem 'jdbc-mysql', require: false
gem 'jdbc-sqlite3', '>= 3.7.2', platform: :jruby
gem 'json', '>=1.6.6'
gem 'omniauth-google-oauth2'
gem 'omniauth-rails_csrf_protection'
gem 'pry', '~> 0.14.0'
gem 'pry-rails', '~> 0.3.9'
gem 'puma'
gem 'rack', '>= 1.1.0'
gem 'rack-attack', '~> 4.0'
gem 'rubyzip', '~> 1.0'
gem 'silencer'
gem 'sucker_punch', '~> 2.0'
gem 'tzinfo-data', platform: :jruby
gem 'warbler', '~> 2.0'
gem 'with_advisory_lock'
gem 'zip-zip'
36 changes: 36 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ GEM
airbrake-ruby (~> 5.1)
airbrake-ruby (5.2.0-java)
rbtree-jruby (~> 0.2)
ast (2.4.2)
bcrypt (3.1.16-java)
builder (3.2.4)
capistrano (2.15.9)
Expand Down Expand Up @@ -214,6 +215,9 @@ GEM
actionpack (>= 4.2)
omniauth (~> 2.0)
orm_adapter (0.5.0)
parallel (1.21.0)
parser (3.1.0.0)
ast (~> 2.4.1)
pry (0.14.1-java)
coderay (~> 1.1)
method_source (~> 1.0)
Expand Down Expand Up @@ -262,14 +266,40 @@ GEM
method_source
rake (>= 0.13)
thor (~> 1.0)
rainbow (3.1.1)
rake (13.0.6)
rb-fsevent (0.11.0)
rb-inotify (0.10.1)
ffi (~> 1.0)
rbtree-jruby (0.2.1)
regexp_parser (2.2.0)
responders (3.0.1)
actionpack (>= 5.0)
railties (>= 5.0)
rexml (3.2.5)
rubocop (1.25.0)
parallel (~> 1.10)
parser (>= 3.1.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.15.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.15.1)
parser (>= 3.0.1.1)
rubocop-minitest (0.17.0)
rubocop (>= 0.90, < 2.0)
rubocop-performance (1.13.2)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.13.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.4)
ruby_parser (3.15.1)
sexp_processor (~> 4.9)
Expand Down Expand Up @@ -316,6 +346,7 @@ GEM
tzinfo (>= 1.0.0)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
unicode-display_width (2.1.0)
warbler (2.0.5)
jruby-jars (>= 9.0.0.0)
jruby-rack (>= 1.1.1, < 1.3)
Expand Down Expand Up @@ -373,6 +404,11 @@ DEPENDENCIES
rails (~> 6.1.4.4)
rails-controller-testing
rake
rubocop
rubocop-minitest
rubocop-performance
rubocop-rails
rubocop-rake
rubyzip (~> 1.0)
sass
sass-rails (~> 5)
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)
require File.expand_path('config/application', __dir__)
require 'rake'

Sosol::Application.load_tasks
110 changes: 55 additions & 55 deletions app/controllers/ajax_proxy_controller.rb
Original file line number Diff line number Diff line change
@@ -1,99 +1,99 @@
class AjaxProxyController < ApplicationController
skip_before_action :verify_authenticity_token, only: [:js, :css, :images]
skip_before_action :verify_authenticity_token, only: %i[js css images]

def index
render :plain => ''
render plain: ''
end

def proxy
response = NumbersRDF::NumbersHelper.identifier_to_numbers_server_response(params[:id].to_s, 'json')
render :plain => response.body, :status => response.code
render plain: response.body, status: response.code
end

def sparql
response = NumbersRDF::NumbersHelper.sparql_query_to_numbers_server_response(params[:query].to_s, 'json')
render :plain => response.body, :status => response.code
render plain: response.body, status: response.code
end

def hgvnum

def hgvnum
related_identifiers = NumbersRDF::NumbersHelper.collection_identifier_to_identifiers(params[:identifier].to_s)

if related_identifiers.nil?
render :plain => "no related identifiers"
render plain: 'no related identifiers'
else
render :plain => "#{related_identifiers.first}"
render plain: related_identifiers.first.to_s
end

end

def js
built_uri = 'http://papyri.info/js/' + params[:query].to_s
response = Net::HTTP.get_response(URI("#{built_uri}"))
render :js => response.body, :layout => false
built_uri = "http://papyri.info/js/#{params[:query]}"
response = Net::HTTP.get_response(URI(built_uri.to_s))
render js: response.body, layout: false
end

def css
built_uri = 'http://papyri.info/css/' + params[:query].to_s
response = Net::HTTP.get_response(URI("#{built_uri}"))
render :plain => response.body, :content_type => 'text/css', :layout => false
built_uri = "http://papyri.info/css/#{params[:query]}"
response = Net::HTTP.get_response(URI(built_uri.to_s))
render plain: response.body, content_type: 'text/css', layout: false
end

def images
built_uri = 'http://papyri.info/images/' + params[:query].to_s
response = Net::HTTP.get_response(URI("#{built_uri}"))
render :plain => response.body, :content_type => response['Content-Type'], :layout => false
built_uri = "http://papyri.info/images/#{params[:query]}"
response = Net::HTTP.get_response(URI(built_uri.to_s))
render plain: response.body, content_type: response['Content-Type'], layout: false
end

# Gets the HTTP response from PN solr query
def get_bibliography
searchText = (params[:searchText].to_s)
#replace space with + to match PN search
searchText = searchText.split(" ").join("+")
searchText = params[:searchText].to_s
# replace space with + to match PN search
searchText = searchText.split.join('+')

begin
built_uri = 'http://papyri.info/solrbiblio/select/?q=' + searchText + '&wt=json&start=0&rows=999&sort=date+asc,sort+asc'
built_uri = "http://papyri.info/solrbiblio/select/?q=#{searchText}&wt=json&start=0&rows=999&sort=date+asc,sort+asc"

response = Net::HTTP.get_response(URI("#{built_uri}"))
response = Net::HTTP.get_response(URI(built_uri.to_s))

render :plain => response.body.html_safe
render plain: response.body.html_safe
rescue ::Timeout::Error => e
render :plain => "rescue timeout bibliography call"
rescue
render :plain => "rescue generic bibliography call"
render plain: 'rescue timeout bibliography call'
rescue StandardError
render plain: 'rescue generic bibliography call'
end
end

def xsugar
response = get_xsugar_response(params)
render :plain => response.body.html_safe, :status => response.code

render plain: response.body.html_safe, status: response.code
end

protected
def get_xsugar_response(params)
xsugar_url = Sosol::Application.config.xsugar_standalone_url if Sosol::Application.config.respond_to?(:xsugar_standalone_url)
begin
if !Sosol::Application.config.respond_to?(:xsugar_standalone_url)
Rails.logger.info("Returning nil for XSugar proxy request as XSugar standalone url is not set")
return nil
else
return Net::HTTP.post_form(URI.parse(xsugar_url),
{
:content => params[:content].to_s,
:type => params[:type].to_s,
:direction => params[:direction].to_s
}
)
end
rescue OpenSSL::SSL::SSLError => e
Rails.logger.info("AjaxProxyController#get_xsugar_response SSLError (#{e.inspect}), falling back to plain HTTP")
parsed_uri = URI.parse(xsugar_url)
parsed_uri.scheme = 'http'
xsugar_url = parsed_uri.to_s
retry
rescue EOFError
get_xsugar_response(params)

def get_xsugar_response(params)
if Sosol::Application.config.respond_to?(:xsugar_standalone_url)
xsugar_url = Sosol::Application.config.xsugar_standalone_url
end
begin
if Sosol::Application.config.respond_to?(:xsugar_standalone_url)
Net::HTTP.post_form(URI.parse(xsugar_url),
{
content: params[:content].to_s,
type: params[:type].to_s,
direction: params[:direction].to_s
})
else
Rails.logger.info('Returning nil for XSugar proxy request as XSugar standalone url is not set')
nil
end
rescue OpenSSL::SSL::SSLError => e
Rails.logger.info("AjaxProxyController#get_xsugar_response SSLError (#{e.inspect}), falling back to plain HTTP")
parsed_uri = URI.parse(xsugar_url)
parsed_uri.scheme = 'http'
xsugar_url = parsed_uri.to_s
retry
rescue EOFError
get_xsugar_response(params)
end
end
end
Loading

0 comments on commit cc0c5e8

Please sign in to comment.