Class: MyObfuscate::Postgres
- Inherits:
-
Object
- Object
- MyObfuscate::Postgres
- Includes:
- ConfigScaffoldGenerator, CopyStatementParser
- Defined in:
- lib/my_obfuscate/postgres.rb
Instance Method Summary collapse
- #make_insert_statement(table_name, column_names, values, ignore = nil) ⇒ Object
- #make_valid_value_string(value) ⇒ Object
- #parse_copy_statement(line) ⇒ Object
- #parse_insert_statement(line) ⇒ Object
-
#rows_to_be_inserted(line) ⇒ Object
Copy statements contain the column values tab separated like so: blah blah blah blah which we want to turn into: [[‘blah’,‘blah’,‘blah’,‘blah’]].
Methods included from ConfigScaffoldGenerator
#config_table_close, #config_table_open, #emit_scaffold, #formatted_line, #generate_config
Methods included from CopyStatementParser
Instance Method Details
#make_insert_statement(table_name, column_names, values, ignore = nil) ⇒ Object
37 38 39 |
# File 'lib/my_obfuscate/postgres.rb', line 37 def make_insert_statement(table_name, column_names, values, ignore = nil) values.join("\t") end |
#make_valid_value_string(value) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/my_obfuscate/postgres.rb', line 41 def make_valid_value_string(value) if value.nil? "\\N" else value end end |
#parse_copy_statement(line) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/my_obfuscate/postgres.rb', line 28 def parse_copy_statement(line) if regex_match = /^\s*COPY (.*?) \((.*?)\) FROM\s*/i.match(line) { :table_name => regex_match[1].to_sym, :column_names => regex_match[2].split(/\s*,\s*/).map(&:to_sym) } end end |
#parse_insert_statement(line) ⇒ Object
49 50 51 |
# File 'lib/my_obfuscate/postgres.rb', line 49 def parse_insert_statement(line) /^\s*INSERT INTO/i.match(line) end |
#rows_to_be_inserted(line) ⇒ Object
Copy statements contain the column values tab separated like so:
blah blah blah blah
which we want to turn into:
[['blah','blah','blah','blah']]
We wrap it in an array to keep it consistent with MySql bulk obfuscation (multiple rows per insert statement)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/my_obfuscate/postgres.rb', line 13 def rows_to_be_inserted(line) row = line.split(/\t/, -1) row.last && row.last.strip! row.collect! do |value| if value == "\\N" nil else value end end [row] end |