Skip to content

Commit

Permalink
Correct rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
that-jill committed Dec 13, 2023
1 parent 1523a10 commit f90c6ea
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 68 deletions.
2 changes: 0 additions & 2 deletions packages/data_taster/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-powerhome

Expand Down
20 changes: 0 additions & 20 deletions packages/data_taster/.rubocop_todo.yml

This file was deleted.

2 changes: 2 additions & 0 deletions packages/data_taster/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
source "https://rubygems.org"

gemspec

gem "rubocop-powerhome", path: "../rubocop-powerhome"
26 changes: 13 additions & 13 deletions packages/data_taster/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
PATH
remote: ../rubocop-powerhome
specs:
rubocop-powerhome (0.5.2)
rubocop (~> 1.52.0)
rubocop-performance
rubocop-rails
rubocop-rake
rubocop-rspec

PATH
remote: .
specs:
Expand Down Expand Up @@ -63,7 +73,6 @@ GEM
tzinfo (~> 1.1)
zeitwerk (~> 2.2, >= 2.2.2)
ast (2.4.2)
base64 (0.1.1)
builder (3.2.4)
concurrent-ruby (1.2.2)
crass (1.0.6)
Expand All @@ -76,7 +85,6 @@ GEM
i18n (1.14.1)
concurrent-ruby (~> 1.0)
json (2.6.3)
language_server-protocol (3.17.0.3)
license_finder (7.1.0)
bundler
rubyzip (>= 1, < 3)
Expand Down Expand Up @@ -170,16 +178,14 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.0)
rubocop (1.56.4)
base64 (~> 0.1.1)
rubocop (1.52.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.3)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.1, < 2.0)
rubocop-ast (>= 1.28.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
Expand All @@ -191,12 +197,6 @@ GEM
rubocop-performance (1.19.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-powerhome (0.5.0)
rubocop
rubocop-performance
rubocop-rails
rubocop-rake
rubocop-rspec
rubocop-rails (2.22.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
Expand Down Expand Up @@ -260,7 +260,7 @@ DEPENDENCIES
rainbow (= 2.2.2)
rake (~> 13.0)
rspec (~> 3.0)
rubocop-powerhome (= 0.5.0)
rubocop-powerhome!
simplecov (= 0.15.1)
test-unit (= 3.1.5)
yard (= 0.9.34)
Expand Down
22 changes: 13 additions & 9 deletions packages/data_taster/lib/data_taster/detergent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,7 @@ def initialize(table_name, column_name, given_value)
def deliver
return value if value == DataTaster::SKIP_CODE

sql = if value.is_a?(Date)
sql_for_date_value
elsif value.is_a?(Numeric) || sanitize_function?
sql_for_uncast_value
elsif value.blank?
sql_for_nil_value
else
sql_for_cast_value
end
sql = sql_for(value)

DataTaster.logger.info("--> #{sql}")
sql
Expand All @@ -49,6 +41,18 @@ def parse_value(given_value)
Date.parse(given_value)
end

def sql_for(value)
if value.is_a?(Date)
sql_for_date_value
elsif value.is_a?(Numeric) || sanitize_function?
sql_for_uncast_value
elsif value.blank?
sql_for_nil_value
else
sql_for_cast_value
end
end

def sanitize_function?
SANITIZE_FUNCTIONS.any? { |fun| value.to_s.match(fun) }
end
Expand Down
26 changes: 14 additions & 12 deletions packages/data_taster/lib/data_taster/flavors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,22 @@ def skip_sanitization
end

def encrypt(klass, column, value = nil)
return klass.new.encrypt(column, value) if value
value_to_encrypt = value || default_value_for(column)

value = case column
when /date_of_birth/, /dob/
(Date.current - 25.years).strftime("%m/%d/%Y")
when /ssn/, /license/
"111111111"
when /compensation/
1
else
"1"
end
klass.new.encrypt(column, value_to_encrypt)
end

klass.new.encrypt(column, value)
def default_value_for(column)
case column
when /date_of_birth/, /dob/
(Date.current - 25.years).strftime("%m/%d/%Y")
when /ssn/, /license/
"111111111"
when /compensation/
1
else
"1"
end
end

def full_table_dump
Expand Down
24 changes: 12 additions & 12 deletions packages/data_taster/lib/data_taster/sanitizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ def clean!
table_name, column_name, sanitized_value
).deliver

if sql == DataTaster::SKIP_CODE
nil
elsif include_insert
process(sql)
else
sql
end
process(sql)
end
end

Expand All @@ -34,9 +28,18 @@ def clean!
attr_reader :table_name, :custom_selections, :include_insert

def process(sql)
return if sql == DataTaster::SKIP_CODE
return sql unless include_insert

DataTaster.safe_execute(sql)
rescue => e
context_warning = <<~WARNING
e.message << context_warning

raise e
end

def context_warning
<<~WARNING
*****
Expand All @@ -45,9 +48,6 @@ def process(sql)
*****
WARNING

e.message << context_warning
raise e
end

def skippable_table?
Expand Down Expand Up @@ -75,7 +75,7 @@ def table_columns
.map(&:name)
end

def defaults
def defaults # rubocop:disable Metrics/MethodLength
{
# `encrypted` should be removed if it is not custom-sanitized
/encrypted/ => "",
Expand Down

0 comments on commit f90c6ea

Please sign in to comment.