Class: StructuredDataToSql::Diagnostic
- Inherits:
-
Object
- Object
- StructuredDataToSql::Diagnostic
- Includes:
- ImmutableValue
- Defined in:
- lib/structured_data_to_sql/diagnostic.rb
Overview
A structured warning: the one-line message that ConversionResult#warnings
has always carried, plus the parts a terminal block or a report needs —
a stable code, a short title, a headline count, a summary, the
complete items list (field names, ids), extra details lines, a
suggested action, and sources (paths to look at). Nothing here holds
member values or per-row payloads.
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#items_label ⇒ Object
readonly
Returns the value of attribute items_label.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
-
#terminal_items ⇒ Object
readonly
Returns the value of attribute terminal_items.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(code:, title:, message:, count: nil, summary: nil, items: [], items_label: nil, terminal_items: true, details: [], action: nil, sources: []) ⇒ Diagnostic
constructor
A new instance of Diagnostic.
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(code:, title:, message:, count: nil, summary: nil, items: [], items_label: nil, terminal_items: true, details: [], action: nil, sources: []) ⇒ Diagnostic
Returns a new instance of Diagnostic.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/structured_data_to_sql/diagnostic.rb', line 27 def initialize( code:, title:, message:, count: nil, summary: nil, items: [], items_label: nil, terminal_items: true, details: [], action: nil, sources: [] ) @code = code.to_sym @title = title.to_s @message = .to_s @count = count @summary = summary @items = deep_freeze(Array(items).map(&:to_s)) @items_label = items_label @terminal_items = terminal_items ? true : false @details = deep_freeze(Array(details).map(&:to_s)) @action = action @sources = deep_freeze(Array(sources).map(&:to_s)) freeze end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
15 16 17 |
# File 'lib/structured_data_to_sql/diagnostic.rb', line 15 def action @action end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
15 16 17 |
# File 'lib/structured_data_to_sql/diagnostic.rb', line 15 def code @code end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
15 16 17 |
# File 'lib/structured_data_to_sql/diagnostic.rb', line 15 def count @count end |
#details ⇒ Object (readonly)
Returns the value of attribute details.
15 16 17 |
# File 'lib/structured_data_to_sql/diagnostic.rb', line 15 def details @details end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
15 16 17 |
# File 'lib/structured_data_to_sql/diagnostic.rb', line 15 def items @items end |
#items_label ⇒ Object (readonly)
Returns the value of attribute items_label.
15 16 17 |
# File 'lib/structured_data_to_sql/diagnostic.rb', line 15 def items_label @items_label end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
15 16 17 |
# File 'lib/structured_data_to_sql/diagnostic.rb', line 15 def @message end |
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
15 16 17 |
# File 'lib/structured_data_to_sql/diagnostic.rb', line 15 def sources @sources end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
15 16 17 |
# File 'lib/structured_data_to_sql/diagnostic.rb', line 15 def summary @summary end |
#terminal_items ⇒ Object (readonly)
Returns the value of attribute terminal_items.
15 16 17 |
# File 'lib/structured_data_to_sql/diagnostic.rb', line 15 def terminal_items @terminal_items end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
15 16 17 |
# File 'lib/structured_data_to_sql/diagnostic.rb', line 15 def title @title end |
Class Method Details
.generic(message) ⇒ Object
54 55 56 |
# File 'lib/structured_data_to_sql/diagnostic.rb', line 54 def self.generic() new(code: :generic, title: "Warning", message: ) end |
.wrap(value) ⇒ Object
58 59 60 |
# File 'lib/structured_data_to_sql/diagnostic.rb', line 58 def self.wrap(value) value.is_a?(Diagnostic) ? value : generic(value.to_s) end |
Instance Method Details
#to_h ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/structured_data_to_sql/diagnostic.rb', line 66 def to_h { code: code, title: title, count: count, summary: summary, items: items, items_label: items_label, terminal_items: terminal_items, details: details, action: action, sources: sources, message: } end |
#to_s ⇒ Object
62 63 64 |
# File 'lib/structured_data_to_sql/diagnostic.rb', line 62 def to_s end |