Class: Pinspec::Inputs::Redactor
- Inherits:
-
Object
- Object
- Pinspec::Inputs::Redactor
- Defined in:
- lib/pinspec/inputs/redactor.rb
Constant Summary collapse
- BUILT_IN =
%w[ email phone phone_number mobile ssn social_security_number dob date_of_birth birthdate first_name last_name full_name middle_name maiden_name address address1 address2 address_line1 address_line2 street city postcode zip zipcode ip_address remote_ip token api_key access_token refresh_token secret password_digest encrypted_password ].freeze
- PERSON_TABLES =
%w[ customers users people contacts employees members clients patients subscribers accounts admins authors owners guests students staff ].freeze
- PERSON_COLUMNS =
%w[name display_name nickname username handle].freeze
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#initialize(attributes: [], enabled: true) ⇒ Redactor
constructor
A new instance of Redactor.
- #reads_in(source, columns) ⇒ Object
- #redact(attrs, ordinal:, table: nil) ⇒ Object
- #redacts?(column_name, table: nil) ⇒ Boolean
Constructor Details
#initialize(attributes: [], enabled: true) ⇒ Redactor
Returns a new instance of Redactor.
18 19 20 21 |
# File 'lib/pinspec/inputs/redactor.rb', line 18 def initialize(attributes: [], enabled: true) @extra = Array(attributes).map(&:to_s) @enabled = enabled end |
Instance Method Details
#enabled? ⇒ Boolean
23 24 25 |
# File 'lib/pinspec/inputs/redactor.rb', line 23 def enabled? @enabled end |
#reads_in(source, columns) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/pinspec/inputs/redactor.rb', line 58 def reads_in(source, columns) return [] unless @enabled Array(columns).uniq.filter_map do |column| line = read_line(source, column.to_s) next unless line { attribute: column.to_s, line: line } end end |
#redact(attrs, ordinal:, table: nil) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pinspec/inputs/redactor.rb', line 43 def redact(attrs, ordinal:, table: nil) redacted = [] rewritten = attrs.each_with_object({}) do |(column, value), out| if redacts?(column, table: table) && value.is_a?(String) && !value.empty? out[column] = rewrite(column.to_s, value, ordinal) redacted << column.to_s else out[column] = value end end [rewritten, redacted] end |
#redacts?(column_name, table: nil) ⇒ Boolean
34 35 36 37 38 39 40 41 |
# File 'lib/pinspec/inputs/redactor.rb', line 34 def redacts?(column_name, table: nil) return false unless @enabled name = column_name.to_s return true if BUILT_IN.include?(name) || @extra.include?(name) PERSON_COLUMNS.include?(name) && PERSON_TABLES.include?(table.to_s) end |