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
16
# 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]
  @count = 0
  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



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

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

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



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

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

#end_logObject



30
31
32
# File 'lib/data_sanity/output.rb', line 30

def end_log
  puts "==> Inspection completed and found #{@count} validation(s) defaulters"
end

#start_log(model) ⇒ Object



26
27
28
# File 'lib/data_sanity/output.rb', line 26

def start_log model
  puts "==> Inspecting :: " + model.to_s
end