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
- #any_errors? ⇒ Boolean
- #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.
8 9 10 11 12 13 14 |
# File 'lib/active_mocker/display_errors.rb', line 8 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.
5 6 7 |
# File 'lib/active_mocker/display_errors.rb', line 5 def errors @errors end |
#failed_models ⇒ Object
Returns the value of attribute failed_models.
6 7 8 |
# File 'lib/active_mocker/display_errors.rb', line 6 def failed_models @failed_models end |
#model_count ⇒ Object (readonly)
Returns the value of attribute model_count.
5 6 7 |
# File 'lib/active_mocker/display_errors.rb', line 5 def model_count @model_count end |
#out ⇒ Object (readonly)
Returns the value of attribute out.
5 6 7 |
# File 'lib/active_mocker/display_errors.rb', line 5 def out @out end |
#success_count ⇒ Object
Returns the value of attribute success_count.
6 7 8 |
# File 'lib/active_mocker/display_errors.rb', line 6 def success_count @success_count end |
Instance Method Details
#add(errors) ⇒ Object
16 17 18 |
# File 'lib/active_mocker/display_errors.rb', line 16 def add(errors) @errors.concat([*errors]) end |
#any_errors? ⇒ Boolean
32 33 34 |
# File 'lib/active_mocker/display_errors.rb', line 32 def any_errors? uniq_errors.count > 0 end |
#display_errors ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/active_mocker/display_errors.rb', line 36 def display_errors uniq_errors.each do |e| next unless ENV["DEBUG"] || !(e.level == :debug) display_verbosity_three(e) || display_verbosity_two(e) end display_verbosity_one end |
#error_summary ⇒ Object
46 47 48 49 50 |
# File 'lib/active_mocker/display_errors.rb', line 46 def error_summary display "Error Summary" display "errors: #{error_count}, warn: #{warn}, info: #{info}" display "Failed models: #{failed_models.join(", ")}" if failed_models.count > 0 end |
#failure_count_message ⇒ Object
52 53 54 55 56 |
# File 'lib/active_mocker/display_errors.rb', line 52 def if success_count < model_count || any_errors? display "#{model_count - success_count} mock(s) out of #{model_count} failed." end end |
#uniq_errors ⇒ Object
28 29 30 |
# File 'lib/active_mocker/display_errors.rb', line 28 def uniq_errors @uniq_errors ||= errors.flatten.compact.uniq.sort_by(&:class_name) end |
#wrap_an_exception(e, model_name) ⇒ Object
24 25 26 |
# File 'lib/active_mocker/display_errors.rb', line 24 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
20 21 22 |
# File 'lib/active_mocker/display_errors.rb', line 20 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 |