Class: Flexr::DiagnosticSet
- Inherits:
-
Object
- Object
- Flexr::DiagnosticSet
- Includes:
- Enumerable
- Defined in:
- lib/flexr/diagnostics.rb
Instance Method Summary collapse
- #<<(diagnostic) ⇒ Object
- #any_error? ⇒ Boolean
- #each ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ DiagnosticSet
constructor
A new instance of DiagnosticSet.
- #render(format: :human, color: :auto) ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize ⇒ DiagnosticSet
Returns a new instance of DiagnosticSet.
28 29 30 |
# File 'lib/flexr/diagnostics.rb', line 28 def initialize @items = [] end |
Instance Method Details
#<<(diagnostic) ⇒ Object
36 37 38 39 |
# File 'lib/flexr/diagnostics.rb', line 36 def <<(diagnostic) @items << diagnostic self end |
#any_error? ⇒ Boolean
41 42 43 |
# File 'lib/flexr/diagnostics.rb', line 41 def any_error? @items.any?(&:error?) end |
#each ⇒ Object
32 33 34 |
# File 'lib/flexr/diagnostics.rb', line 32 def each(&) @items.each(&) end |
#empty? ⇒ Boolean
45 46 47 |
# File 'lib/flexr/diagnostics.rb', line 45 def empty? @items.empty? end |
#render(format: :human, color: :auto) ⇒ Object
53 54 55 56 57 |
# File 'lib/flexr/diagnostics.rb', line 53 def render(format: :human, color: :auto) return JSON.generate(@items.map(&:to_h)) if format.to_sym == :json @items.map { |item| render_one(item, color: color_enabled?(color)) }.join("\n") end |
#to_a ⇒ Object
49 50 51 |
# File 'lib/flexr/diagnostics.rb', line 49 def to_a @items.dup end |