Class: DataSanity::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/data_sanity/output.rb

Constant Summary collapse

OPTIONS =
[:table, :csv]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Output

Returns a new instance of Output.

Raises:

  • (Exception)


8
9
10
11
12
13
14
15
# File 'lib/data_sanity/output.rb', line 8

def initialize options = {}
  raise Exception.new("This options to output the result of inspector is not valid") unless OPTIONS.include?(options[:option])
  self.option = options[:option]
  if self.option == :csv
    self.csv_file = FasterCSV.open("#{Rails.root}/tmp/data_inspector.csv", 'w') 
    self.csv_file.add_row ['table_name', 'table_primary_key', 'primary_key_value', 'validation_errors']
  end
end

Instance Attribute Details

#csv_fileObject

Returns the value of attribute csv_file.



7
8
9
# File 'lib/data_sanity/output.rb', line 7

def csv_file
  @csv_file
end

#optionObject

Returns the value of attribute option.



7
8
9
# File 'lib/data_sanity/output.rb', line 7

def option
  @option
end

Instance Method Details

#closeObject



21
22
23
# File 'lib/data_sanity/output.rb', line 21

def close
  self.csv_file.close_write if self.csv_file
end

#create_from(model, instance, exception = nil) ⇒ Object



17
18
19
# File 'lib/data_sanity/output.rb', line 17

def create_from model, instance, exception = nil
  send("store_to_#{self.option}", model, instance, exception)
end