Skip to content

Commit

Permalink
Fix Violations of and Reenable Style/HashTransformValues and `Style…
Browse files Browse the repository at this point in the history
…/HashTransformKeys` (#58453)

* fix violations of and reenable Style/HashTransformValues

* fix violations of and reenable Style/HashTransformKeys
  • Loading branch information
Hamms committed May 13, 2024
1 parent 9d21c98 commit f09898e
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 29 deletions.
10 changes: 0 additions & 10 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,6 @@ Style/GlobalVars:
Style/HashLikeCase:
Enabled: false

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/HashTransformKeys:
Enabled: false

# Offense count: 12
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/HashTransformValues:
Enabled: false

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowedMethods.
Expand Down
6 changes: 3 additions & 3 deletions bin/i18n/resources/dashboard/course_content/sync_in.rb
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,9 @@ def process
source_data = JSON.load_file(source_path)
return if source_data.blank?

redactable_data = source_data.map do |level_url, i18n_strings|
[level_url, select_redactable(i18n_strings)]
end.to_h
redactable_data = source_data.transform_values do |i18n_strings|
select_redactable(i18n_strings)
end

backup_path = source_path.sub('source', 'original')
I18nScriptUtils.write_json_file(backup_path, redactable_data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ end
AWS::S3.process_file('cdo-nces', "#{SURVEY_YEAR}/ccd/school_stats_201718.csv") do |filename|
SchoolStatsByYear.transaction do
SchoolStatsByYear.merge_from_csv(filename, {col_sep: ",", headers: true, quote_char: "\x00"}) do |row|
row = row.to_h.map {|k, v| [k, sanitize_string_for_db(v)]}.to_h
row = row.to_h.transform_values {|v| sanitize_string_for_db(v)}

{
school_id: row['School ID - NCES Assigned [Public School] Latest available year'].to_i.to_s,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ end
AWS::S3.process_file('cdo-nces', "#{SURVEY_YEAR}/ccd/School_lvl_demo.csv") do |filename|
SchoolStatsByYear.transaction do
SchoolStatsByYear.merge_from_csv(filename, {col_sep: ",", headers: true, quote_char: "\x00"}) do |row|
row = row.to_h.map {|k, v| [k, sanitize_string_for_db(v)]}.to_h
row = row.to_h.transform_values {|v| sanitize_string_for_db(v)}

{
school_id: row['School ID - NCES Assigned [Public School] Latest available year'].to_i.to_s,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ end
AWS::S3.process_file('cdo-nces', "#{SURVEY_YEAR}/ccd/schools.csv") do |filename|
SchoolStatsByYear.merge_from_csv(filename, {col_sep: ",", headers: true, quote_char: "\x00", encoding: 'UTF-8'}, dry_run: DRY_RUN) do |row|
# remove quote and eq sign from ="12345"
row = row.to_h.map {|k, v| [k, sanitize_string_for_db(v)]}.to_h
row = row.to_h.transform_values {|v| sanitize_string_for_db(v)}

{
school_id: row['School ID - NCES Assigned [Public School] Latest available year'].to_i.to_s,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ end
AWS::S3.process_file('cdo-nces', "#{SURVEY_YEAR}/ccd/schools_public.csv") do |filename|
SchoolStatsByYear.merge_from_csv(filename, {col_sep: ",", headers: true, quote_char: "\x00", encoding: 'UTF-8'}, dry_run: DRY_RUN) do |row|
# remove quote and eq sign from ="12345"
row = row.to_h.map {|k, v| [k, sanitize_string_for_db(v)]}.to_h
row = row.to_h.transform_values {|v| sanitize_string_for_db(v)}

{
school_id: row['School ID - NCES Assigned [Public School] Latest available year'].to_i.to_s,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ end
AWS::S3.process_file('cdo-nces', "#{SURVEY_YEAR}/ccd/schools_public.csv") do |filename|
SchoolStatsByYear.merge_from_csv(filename, {col_sep: ",", headers: true, quote_char: "\x00", encoding: 'bom|utf-8'}, dry_run: DRY_RUN) do |row|
# remove quote and eq sign from ="12345"
row = row.to_h.map {|k, v| [k, sanitize_string_for_db(v)]}.to_h
row = row.to_h.transform_values {|v| sanitize_string_for_db(v)}

{
school_id: row['School ID - NCES Assigned [Public School] Latest available year'].to_i.to_s,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ end
AWS::S3.process_file('cdo-nces', "#{SURVEY_YEAR}/ccd/schools_public.csv") do |filename|
SchoolStatsByYear.merge_from_csv(filename, {col_sep: ",", headers: true, quote_char: "\x00", encoding: 'bom|utf-8'}, dry_run: DRY_RUN) do |row|
# remove quote and eq sign from ="12345" (the ="" is required to preserve leading 0's in zip codes)
row = row.to_h.map {|k, v| [k, sanitize_string_for_db(v)]}.to_h
row = row.to_h.transform_values {|v| sanitize_string_for_db(v)}
school_id = row['School ID - NCES Assigned [Public School] Latest available year'].to_i.to_s
# NCES did not provide Title 1 Status in the table this year so we are using last year's as a placeholder
previous_year_entry = SchoolStatsByYear.where(school_id: school_id, school_year: LAST_SURVEY_YEAR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ def report_csv
where(submitter_id: enrollments.map(&:user_id)).
pluck(:submitter_id, :script_id, :level_id, :created_at).
group_by {|pr| pr[0..2]}. # group by [submitter_id, script_id, level_id]
map {|k, prs| [k, prs.map {|pr| pr[3]}]}. # only keep :created_at in values
to_h
transform_values {|prs| prs.map {|pr| pr[3]}} # only keep :created_at in values

enrollments.each do |enrollment|
peer_review_submissions = Hash.new
Expand Down
6 changes: 3 additions & 3 deletions dashboard/app/models/foorm/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ def associated_facilitator_submissions
def formatted_answers_with_facilitator_number(number)
return {} unless workshop_metadata.facilitator_specific?

formatted_answers.map do |question_id, answer_text|
[question_id + "_#{number}", answer_text]
end.to_h
formatted_answers.transform_keys do |question_id|
question_id + "_#{number}"
end
end

# Store the JSON parsable "{}" if we attempt to store a blank submission,
Expand Down
8 changes: 4 additions & 4 deletions dashboard/app/models/school.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def self.seed_from_s3
CDO.log.info "Seeding 2019-2020 public school data."
AWS::S3.seed_from_file('cdo-nces', "2019-2020/ccd/schools.csv") do |filename|
merge_from_csv(filename, {headers: true, quote_char: "\x00"}, true, is_dry_run: false, ignore_attributes: ['last_known_school_year_open']) do |row|
row = row.to_h.map {|k, v| [k, sanitize_string_for_db(v)]}.to_h
row = row.to_h.transform_values {|v| sanitize_string_for_db(v)}
{
id: row['School ID - NCES Assigned [Public School] Latest available year'].to_i.to_s,
name: row['School Name'].upcase,
Expand All @@ -349,7 +349,7 @@ def self.seed_from_s3
CDO.log.info "Seeding 2020-2021 public school data."
AWS::S3.seed_from_file('cdo-nces', "2020-2021/ccd/schools_public.csv") do |filename|
merge_from_csv(filename, {headers: true, quote_char: "\x00"}, true, is_dry_run: false, ignore_attributes: ['last_known_school_year_open']) do |row|
row = row.to_h.map {|k, v| [k, sanitize_string_for_db(v)]}.to_h
row = row.to_h.transform_values {|v| sanitize_string_for_db(v)}
{
id: row['School ID - NCES Assigned [Public School] Latest available year'].to_i.to_s,
name: row['School Name'].upcase,
Expand Down Expand Up @@ -404,7 +404,7 @@ def self.seed_from_s3
CDO.log.info "Seeding 2021-2022 public school data."
AWS::S3.seed_from_file('cdo-nces', "2021-2022/ccd/schools_public.csv") do |filename|
merge_from_csv(filename, {headers: true, quote_char: "\x00", encoding: 'bom|utf-8'}, true, is_dry_run: false, ignore_attributes: ['last_known_school_year_open']) do |row|
row = row.to_h.map {|k, v| [k, sanitize_string_for_db(v)]}.to_h
row = row.to_h.transform_values {|v| sanitize_string_for_db(v)}
{
id: row['School ID - NCES Assigned [Public School] Latest available year'].to_i.to_s,
name: row['School Name'].upcase,
Expand All @@ -428,7 +428,7 @@ def self.seed_from_s3
CDO.log.info "Seeding 2022-2023 public school data."
AWS::S3.seed_from_file('cdo-nces', "2022-2023/ccd/schools_public.csv") do |filename|
merge_from_csv(filename, {headers: true, quote_char: "\x00", encoding: 'bom|utf-8'}, true, is_dry_run: false, ignore_attributes: ['last_known_school_year_open']) do |row|
row = row.to_h.map {|k, v| [k, sanitize_string_for_db(v)]}.to_h
row = row.to_h.transform_values {|v| sanitize_string_for_db(v)}
{
id: row['School ID - NCES Assigned [Public School] Latest available year'].to_i.to_s,
name: row['School Name'].upcase,
Expand Down
2 changes: 1 addition & 1 deletion dashboard/lib/core_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module CoreExtensions
module Hash
module Camelizing
def camelize_keys
map {|key, value| [key.to_s.camelize(:lower), value]}.to_h
transform_keys {|key| key.to_s.camelize(:lower)}
end
end
end
Expand Down

0 comments on commit f09898e

Please sign in to comment.