Class: DataSanity::Inspector

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

Constant Summary collapse

CONSIDERED_RECORDS =
1
ALLOWED_VALIDATION =
[:all, :random, :criteria]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Inspector

Returns a new instance of Inspector.



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

def initialize options = {}
  @output = DataSanity::Output.new :option => ( options[:strategy] || :table ).to_sym
  options[:validate] == "random" ? @random = true : @all = true
  @records_per_model = options[:records_per_model].to_i == 0 ? CONSIDERED_RECORDS : options[:records_per_model].to_i
  @models = load_models
  file_path = "#{Rails.root}/config/data_sanity_criteria.yml"
  @criteria = (File.exists?(file_path) ? (YAML.load File.open(file_path).read) : false) rescue false
end

Instance Attribute Details

#allObject

Returns the value of attribute all.



6
7
8
# File 'lib/data_sanity/inspector.rb', line 6

def all
  @all
end

#criteriaObject

Returns the value of attribute criteria.



6
7
8
# File 'lib/data_sanity/inspector.rb', line 6

def criteria
  @criteria
end

#modelsObject

Returns the value of attribute models.



6
7
8
# File 'lib/data_sanity/inspector.rb', line 6

def models
  @models
end

#outputObject

Returns the value of attribute output.



6
7
8
# File 'lib/data_sanity/inspector.rb', line 6

def output
  @output
end

#randomObject

Returns the value of attribute random.



6
7
8
# File 'lib/data_sanity/inspector.rb', line 6

def random
  @random
end

#records_per_modelObject

Returns the value of attribute records_per_model.



6
7
8
# File 'lib/data_sanity/inspector.rb', line 6

def records_per_model
  @records_per_model
end

Instance Method Details

#investigateObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/data_sanity/inspector.rb', line 17

def investigate
  if @all
    considered_models = @criteria ? @criteria.keys : @models
    considered_models.each do |model_string|
      model = model_string.constantize
      @output.start_log model
      validate_all(model)
      @output.end_log
    end
  elsif @criteria
    @criteria.keys.each do |model|
      @output.start_log model
      validate_criteria(model.constantize, @criteria[model])
      @output.end_log
    end
  else
    @models.each do |model_string|
      @output.start_log model_string
      validate_random(model_string.constantize)
      @output.end_log
    end
  end
  @output.close
end