Class: DataSanity::Inspector
- Inherits:
-
Object
- Object
- DataSanity::Inspector
- Defined in:
- lib/data_sanity/inspector.rb
Constant Summary collapse
- CONSIDERED_RECORDS =
1
- ALLOWED_VALIDATION =
[:all, :random, :criteria]
Instance Attribute Summary collapse
-
#all ⇒ Object
Returns the value of attribute all.
-
#criteria ⇒ Object
Returns the value of attribute criteria.
-
#models ⇒ Object
Returns the value of attribute models.
-
#output ⇒ Object
Returns the value of attribute output.
-
#random ⇒ Object
Returns the value of attribute random.
-
#records_per_model ⇒ Object
Returns the value of attribute records_per_model.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Inspector
constructor
A new instance of Inspector.
- #investigate ⇒ Object
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 = {} @output = DataSanity::Output.new :option => ( [:strategy] || :table ).to_sym [:validate] == "random" ? @random = true : @all = true @records_per_model = [:records_per_model].to_i == 0 ? CONSIDERED_RECORDS : [: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
#all ⇒ Object
Returns the value of attribute all.
6 7 8 |
# File 'lib/data_sanity/inspector.rb', line 6 def all @all end |
#criteria ⇒ Object
Returns the value of attribute criteria.
6 7 8 |
# File 'lib/data_sanity/inspector.rb', line 6 def criteria @criteria end |
#models ⇒ Object
Returns the value of attribute models.
6 7 8 |
# File 'lib/data_sanity/inspector.rb', line 6 def models @models end |
#output ⇒ Object
Returns the value of attribute output.
6 7 8 |
# File 'lib/data_sanity/inspector.rb', line 6 def output @output end |
#random ⇒ Object
Returns the value of attribute random.
6 7 8 |
# File 'lib/data_sanity/inspector.rb', line 6 def random @random end |
#records_per_model ⇒ Object
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
#investigate ⇒ Object
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 |