Class: DataTaster::Detergent

Inherits:
Object
  • Object
show all
Defined in:
lib/data_taster/detergent.rb

Overview

Returns SQL for given data, based on types. Used for sanitizing inputs.

Constant Summary collapse

SANITIZE_FUNCTIONS =
[
  /CONCAT/,
  /DATE/,
  /DAY/,
  /FORMAT/,
  /LOWER/,
  /REPLACE/,
  /TRIM/,
  /UCASE/,
  /UPPER/,
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(table_name, column_name, given_value) ⇒ Detergent

Returns a new instance of Detergent.



18
19
20
21
22
# File 'lib/data_taster/detergent.rb', line 18

def initialize(table_name, column_name, given_value)
  @table_name = table_name
  @column_name = column_name
  @value = parse_value(given_value)
end

Instance Method Details

#deliverObject



24
25
26
27
28
29
30
31
# File 'lib/data_taster/detergent.rb', line 24

def deliver
  return value if value == DataTaster::SKIP_CODE

  sql = sql_for(value)

  DataTaster.logger.info("--> #{sql}")
  sql
end