Skip to content

Commit

Permalink
Made rubocop happy
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminfaure committed Apr 9, 2024
1 parent 03365f4 commit c5df391
Show file tree
Hide file tree
Showing 23 changed files with 54 additions and 36 deletions.
6 changes: 3 additions & 3 deletions app/controllers/api/v0/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def update
#
# Returns Object
def retrieve_resource
instance_variable_get("@#{resource_name}")
instance_variable_get(:"@#{resource_name}")
end

# The allowed parameters for searching. Override this method in each API
Expand Down Expand Up @@ -98,13 +98,13 @@ def resource_name
# the method "#{resource_name}_params" to limit permitted
# parameters for the individual model.
def resource_params
@resource_params ||= send("#{resource_name}_params")
@resource_params ||= send(:"#{resource_name}_params")
end

# Use callbacks to share common setup or constraints between actions.
def define_resource(resource = nil)
resource ||= resource_class.find(params[:id])
instance_variable_set("@#{resource_name}", resource)
instance_variable_set(:"@#{resource_name}", resource)
end

def authenticate
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def current_locale
def store_location
# store last url - this is needed for post-login redirect to whatever the user last
# visited.
# don't store ajax calls
unless ['/users/sign_in',
'/users/sign_up',
'/users/password',
'/users/invitation/accept'].any? { |ur| request.fullpath.include?(ur) } \
|| request.xhr? # don't store ajax calls
'/users/invitation/accept'].any? { |ur| request.fullpath.include?(ur) } || request.xhr?
session[:previous_url] = request.fullpath
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/versionable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def get_new(obj)
else
found = find_in_space(obj.send(belongs), new_template.phases)
obj = obj.send(:deep_copy)
obj.send("#{belongs}=", found)
obj.send(:"#{belongs}=", found)
end
end
obj
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def show
.joins(:templates)
.where(templates: { published: true }).uniq.sort_by(&:name)
# TODO: Seems strange to do this. Why are we just not using an `edit` route?
@editing = (!params[:editing].nil? && @plan.administerable_by?(current_user.id))
@editing = !params[:editing].nil? && @plan.administerable_by?(current_user.id)

# Get all Guidance Groups applicable for the plan and group them by org
@all_guidance_groups = @plan.guidance_group_options
Expand Down
9 changes: 4 additions & 5 deletions app/helpers/conditions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,10 @@ def num_section_questions(plan, section, phase = nil)
def sections_info(plan)
return [] if plan.nil?

info = []
plan.sections.each do |section|
info.push(section_info(plan, section))
info = plan.sections.map do |section|
section_info(plan, section)
end
info
info || []
end

def section_info(plan, section)
Expand Down Expand Up @@ -250,7 +249,7 @@ def conditions_to_param_form(conditions)
def webhook_hash(conditions)
web_hash = {}
param_conditions = conditions_to_param_form(conditions)
param_conditions.each do |_title, params|
param_conditions.each_value do |params|
web_hash.merge!(params[:number] => params[:webhook_data])
end
web_hash
Expand Down
2 changes: 1 addition & 1 deletion app/models/application_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def safe_regexp_where_clause(column:)

def sanitize_fields(*attrs)
attrs.each do |attr|
send("#{attr}=", ActionController::Base.helpers.sanitize(send(attr)))
send(:"#{attr}=", ActionController::Base.helpers.sanitize(send(attr)))
end
end
end
2 changes: 1 addition & 1 deletion app/models/concerns/acts_as_sortable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module ActsAsSortable
class_methods do
def update_numbers!(ids, parent:)
# Ensure only records belonging to this parent are included.
ids = ids.map(&:to_i) & parent.public_send("#{model_name.singular}_ids")
ids = ids.map(&:to_i) & parent.public_send(:"#{model_name.singular}_ids")
return if ids.empty?

update_numbers_postgresql!(ids) if ApplicationRecord.postgres_db?
Expand Down
4 changes: 2 additions & 2 deletions app/models/concerns/exportable_plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ def record_plan_export(user, format)
ep.format = format
plan_settings = settings(:export)

Settings::Template::DEFAULT_SETTINGS.each do |key, _value|
ep.settings(:export).send("#{key}=", plan_settings.send(key))
Settings::Template::DEFAULT_SETTINGS.each_key do |key|
ep.settings(:export).send(:"#{key}=", plan_settings.send(key))
end
end
exported_plan.save
Expand Down
18 changes: 9 additions & 9 deletions app/models/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,34 +208,33 @@ def update_conditions(param_conditions, old_to_new_opts, question_id_map)
conditions.destroy_all
return unless param_conditions.present?

param_conditions.each do |_key, value|
param_conditions.each_value do |value|
save_condition(value, old_to_new_opts, question_id_map)
end
end

# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def save_condition(value, opt_map, question_id_map)
c = conditions.build
c.action_type = value['action_type']
c.number = value['number']
# question options may have changed so rewrite them
c.option_list = value['question_option']
unless opt_map.blank?
new_question_options = []
c.option_list.each do |qopt|
new_question_options << opt_map[qopt]
new_question_options = c.option_list.map do |qopt|
opt_map[qopt]
end
c.option_list = new_question_options
c.option_list = new_question_options || []
end

if value['action_type'] == 'remove'
c.remove_data = value['remove_question_id']
unless question_id_map.blank?
new_question_ids = []
c.remove_data.each do |qid|
new_question_ids << question_id_map[qid]
new_question_ids = c.remove_data.each do |qid|
question_id_map[qid]
end
c.remove_data = new_question_ids
c.remove_data = new_question_ids || []
end
else
c.webhook_data = {
Expand All @@ -247,6 +246,7 @@ def save_condition(value, opt_map, question_id_map)
end
c.save
end
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize

private
Expand Down
4 changes: 2 additions & 2 deletions app/models/research_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ class ResearchOutput < ApplicationRecord

# Helper method to convert selected repository form params into Repository objects
def repositories_attributes=(params)
params.each do |_i, repository_params|
params.each_value do |repository_params|
repositories << Repository.find_by(id: repository_params[:id])
end
end

# Helper method to convert selected metadata standard form params into MetadataStandard objects
def metadata_standards_attributes=(params)
params.each do |_i, metadata_standard_params|
params.each_value do |metadata_standard_params|
metadata_standards << MetadataStandard.find_by(id: metadata_standard_params[:id])
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def deep_copy(attributes: {}, **options)
copy = dup
if attributes.respond_to?(:each_pair)
attributes.each_pair do |attribute, value|
copy.send("#{attribute}=".to_sym, value) if copy.respond_to?("#{attribute}=".to_sym)
copy.send(:"#{attribute}=".to_sym, value) if copy.respond_to?(:"#{attribute}=".to_sym)
end
end
copy.save! if options.fetch(:save, false)
Expand Down
14 changes: 14 additions & 0 deletions config/credentials.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# aws:
# access_key_id: 123
# secret_access_key: 345

# Used as the base secret for all MessageVerifiers in Rails, including the one protecting cookies.
secret_key_base: 3c5a0101d3521a0dae9682b8b4fb1352cacbe18723ae76ff9eaaf1652f548d1e54d242f1e95d05b58262603ecd19ffa8452da2b943df119aa44aa83cf2b81fc1

devise_pepper: de451fa8d44af2c286d922f753d1b10fd23b99c10747143d9ba118988b9fa9601fea66bfe31266ffc6a331dc7331c71ebe845af8abcdb84c24b42b8063386530

dragonfly_secret: "my_secret"

recaptcha:
site_key: 6LcxyFMUAAAAACqaczujD9XBhYLoZ-QNS0ngzMME
secret_key: 6LcxyFMUAAAAAEE2E6jXgoJfXV0viwaYNv6JvePg
1 change: 1 addition & 0 deletions config/initializers/application_controller_renderer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# ActiveSupport::Reloader.to_prepare do
Expand Down
1 change: 1 addition & 0 deletions config/initializers/backtrace_silencers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# You can add backtrace silencers for libraries that you're using but don't
Expand Down
1 change: 1 addition & 0 deletions config/initializers/inflections.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# Add new inflection rules using the following format. Inflections
Expand Down
1 change: 1 addition & 0 deletions config/initializers/mime_types.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.

# Add new mime types for use in respond_to blocks:
Expand Down
1 change: 1 addition & 0 deletions config/initializers/new_framework_defaults_5_2.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.
#
# This file contains migration options to ease your Rails 5.2 upgrade.
Expand Down
1 change: 1 addition & 0 deletions config/initializers/new_framework_defaults_6_1.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# Be sure to restart your server when you modify this file.
#
# This file contains migration options to ease your Rails 6.1 upgrade.
Expand Down
1 change: 1 addition & 0 deletions config/initializers/permissions_policy.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# Define an application-wide HTTP permissions policy. For further
# information see https://developers.google.com/web/updates/2018/06/feature-policy
#
Expand Down
4 changes: 1 addition & 3 deletions lib/tasks/data_cleanup.rake
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ namespace :data_cleanup do
# rubocop:disable Metrics/AbcSize
def check_uniqueness(klass, filter)
instance = klass.new
group = [filter.attributes.map { |a| instance.respond_to?("#{a}_id") ? "#{a}_id".to_sym : a }]
group = [filter.attributes.map { |a| instance.respond_to?(:"#{a}_id") ? :"#{a}_id".to_sym : a }]

group << filter.options[:scope] if filter.options[:scope].present?
group = group.flatten.uniq
Expand Down Expand Up @@ -281,9 +281,7 @@ namespace :data_cleanup do

ids = klass.where(qry).pluck(:id)
msg = " #{ids.count} records that are an invalid #{filter.attributes} because it should #{shoulda}"
# rubocop:disable Lint/Void
[ids, msg]
# rubocop:enable Lint/Void
end
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
Expand Down
6 changes: 3 additions & 3 deletions lib/tasks/migrate.rake
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace :migrate do
name: 'grant_api_to_orgs'
}
}
roles.each do |_r, details|
roles.each_value do |details|
next unless Role.where(name: details[:name]).empty?

role = Role.new
Expand Down Expand Up @@ -141,7 +141,7 @@ namespace :migrate do
}
}

languages.each do |_l, details|
languages.each_value do |details|
next unless Language.where(name: details[:name]).empty?

language = Language.new
Expand Down Expand Up @@ -171,7 +171,7 @@ namespace :migrate do
}
}

regions.each do |_l, details|
regions.each_value do |details|
next unless Region.where(name: details[:name]).empty?

region = Region.new
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/upgrade.rake
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ namespace :upgrade do
.where('customization_of IS NOT NULL')
.group(:customization_of, :org_id, :version, :id)
.order(customization_of: :asc, org_id: :asc, version: :asc, updated_at: :desc)
generate_compound_key = ->(customization_of, org_id) { return "#{customization_of}_#{org_id}" }
generate_compound_key = ->(customization_of, org_id) { "#{customization_of}_#{org_id}" }
current = nil
unique_versions = Set.new
duplicates = []
Expand Down
2 changes: 1 addition & 1 deletion spec/support/helpers/webmocks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def stub_rdamsc_service(successful: true, response_body: '')
def stub_openaire
url = ExternalApis::OpenAireService.api_base_url
url = "#{url}#{ExternalApis::OpenAireService.search_path}"
url = url % ExternalApis::OpenAireService.default_funder
url %= ExternalApis::OpenAireService.default_funder
stub_request(:get, url).to_return(status: 200, body: '', headers: {})
end

Expand Down

0 comments on commit c5df391

Please sign in to comment.