Class: ActiveMocker::DisplayErrors
- Inherits:
-
Object
- Object
- ActiveMocker::DisplayErrors
- Defined in:
- lib/active_mocker/display_errors.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#failed_models ⇒ Object
Returns the value of attribute failed_models.
-
#model_count ⇒ Object
readonly
Returns the value of attribute model_count.
-
#out ⇒ Object
readonly
Returns the value of attribute out.
-
#success_count ⇒ Object
Returns the value of attribute success_count.
Instance Method Summary collapse
- #add(errors) ⇒ Object
- #display_errors ⇒ Object
- #error_summary ⇒ Object
- #failure_count_message ⇒ Object
-
#initialize(model_count, out: STDERR) ⇒ DisplayErrors
constructor
A new instance of DisplayErrors.
- #uniq_errors ⇒ Object
- #wrap_an_exception(e, model_name) ⇒ Object
- #wrap_errors(errors, model_name, type: nil) ⇒ Object
Constructor Details
#initialize(model_count, out: STDERR) ⇒ DisplayErrors
Returns a new instance of DisplayErrors.
7 8 9 10 11 12 13 |
# File 'lib/active_mocker/display_errors.rb', line 7 def initialize(model_count, out: STDERR) @errors = [] @success_count = 0 @model_count = model_count @failed_models = [] @out = out end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
4 5 6 |
# File 'lib/active_mocker/display_errors.rb', line 4 def errors @errors end |
#failed_models ⇒ Object
Returns the value of attribute failed_models.
5 6 7 |
# File 'lib/active_mocker/display_errors.rb', line 5 def failed_models @failed_models end |
#model_count ⇒ Object (readonly)
Returns the value of attribute model_count.
4 5 6 |
# File 'lib/active_mocker/display_errors.rb', line 4 def model_count @model_count end |
#out ⇒ Object (readonly)
Returns the value of attribute out.
4 5 6 |
# File 'lib/active_mocker/display_errors.rb', line 4 def out @out end |
#success_count ⇒ Object
Returns the value of attribute success_count.
5 6 7 |
# File 'lib/active_mocker/display_errors.rb', line 5 def success_count @success_count end |
Instance Method Details
#add(errors) ⇒ Object
15 16 17 |
# File 'lib/active_mocker/display_errors.rb', line 15 def add(errors) @errors.concat([*errors]) end |
#display_errors ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/active_mocker/display_errors.rb', line 31 def display_errors uniq_errors.each do |e| next unless ENV["DEBUG"] || !(e.level == :debug) if ActiveMocker::Config.error_verbosity == 3 out.puts "#{e.class_name} has the following errors:" out.puts e..colorize(e.level_color) out.puts e.level out.puts e.original_error..colorize(e.level_color) if e.original_error? out.puts e.original_error.backtrace if e.original_error? out.puts e.original_error.class.name.colorize(e.level_color) if e.original_error? elsif ActiveMocker::Config.error_verbosity == 2 out.puts "#{e.class_name} has the following errors:" out.puts e..colorize(e.level_color) end end if ActiveMocker::Config.error_verbosity > 0 && uniq_errors.count > 0 out.puts "Error Summary" error_summary end if ActiveMocker::Config.error_verbosity > 0 && uniq_errors.count > 0 out.puts "To see more/less detail set error_verbosity = 0, 1, 2, 3" end end |
#error_summary ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/active_mocker/display_errors.rb', line 56 def error_summary error_count = uniq_errors.count { |e| [:red].include?(e.level_color) } warn = uniq_errors.count { |e| [:yellow].include?(e.level_color) } info = uniq_errors.count { |e| [:default].include?(e.level_color) } out.puts "errors: #{error_count}, warn: #{warn}, info: #{info}" out.puts "Failed models: #{failed_models.join(", ")}" if failed_models.count > 0 end |
#failure_count_message ⇒ Object
64 65 66 67 68 |
# File 'lib/active_mocker/display_errors.rb', line 64 def if ActiveMocker::Config.error_verbosity > 0 && (success_count < model_count || uniq_errors.count > 0) out.puts "#{model_count - success_count} mock(s) out of #{model_count} failed." end end |
#uniq_errors ⇒ Object
27 28 29 |
# File 'lib/active_mocker/display_errors.rb', line 27 def uniq_errors @uniq_errors ||= errors.flatten.compact.uniq.sort_by(&:class_name) end |
#wrap_an_exception(e, model_name) ⇒ Object
23 24 25 |
# File 'lib/active_mocker/display_errors.rb', line 23 def wrap_an_exception(e, model_name) add ErrorObject.build_from(exception: e, class_name: model_name) end |
#wrap_errors(errors, model_name, type: nil) ⇒ Object
19 20 21 |
# File 'lib/active_mocker/display_errors.rb', line 19 def wrap_errors(errors, model_name, type: nil) add errors.map { |e| ErrorObject.build_from(object: e, class_name: model_name, type: type ? type : e.try(:type)) } end |