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.
6 7 8 9 10 11 12 |
# File 'lib/active_mocker/display_errors.rb', line 6 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.
3 4 5 |
# File 'lib/active_mocker/display_errors.rb', line 3 def errors @errors end |
#failed_models ⇒ Object
Returns the value of attribute failed_models.
4 5 6 |
# File 'lib/active_mocker/display_errors.rb', line 4 def failed_models @failed_models end |
#model_count ⇒ Object (readonly)
Returns the value of attribute model_count.
3 4 5 |
# File 'lib/active_mocker/display_errors.rb', line 3 def model_count @model_count end |
#out ⇒ Object (readonly)
Returns the value of attribute out.
3 4 5 |
# File 'lib/active_mocker/display_errors.rb', line 3 def out @out end |
#success_count ⇒ Object
Returns the value of attribute success_count.
4 5 6 |
# File 'lib/active_mocker/display_errors.rb', line 4 def success_count @success_count end |
Instance Method Details
#add(errors) ⇒ Object
14 15 16 |
# File 'lib/active_mocker/display_errors.rb', line 14 def add(errors) @errors.concat([*errors]) end |
#display_errors ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/active_mocker/display_errors.rb', line 30 def display_errors uniq_errors.each do |e| next if e.level == :debug unless ENV["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
55 56 57 58 59 60 61 |
# File 'lib/active_mocker/display_errors.rb', line 55 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
63 64 65 66 67 |
# File 'lib/active_mocker/display_errors.rb', line 63 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
26 27 28 |
# File 'lib/active_mocker/display_errors.rb', line 26 def uniq_errors @uniq_errors ||= errors.flatten.compact.uniq.sort_by(&:class_name) end |
#wrap_an_exception(e, model_name) ⇒ Object
22 23 24 |
# File 'lib/active_mocker/display_errors.rb', line 22 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
18 19 20 |
# File 'lib/active_mocker/display_errors.rb', line 18 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 |