Class: StructuredDataToSql::Diagnostic

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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 = 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

#actionObject (readonly)

Returns the value of attribute action.



15
16
17
# File 'lib/structured_data_to_sql/diagnostic.rb', line 15

def action
  @action
end

#codeObject (readonly)

Returns the value of attribute code.



15
16
17
# File 'lib/structured_data_to_sql/diagnostic.rb', line 15

def code
  @code
end

#countObject (readonly)

Returns the value of attribute count.



15
16
17
# File 'lib/structured_data_to_sql/diagnostic.rb', line 15

def count
  @count
end

#detailsObject (readonly)

Returns the value of attribute details.



15
16
17
# File 'lib/structured_data_to_sql/diagnostic.rb', line 15

def details
  @details
end

#itemsObject (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_labelObject (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

#messageObject (readonly)

Returns the value of attribute message.



15
16
17
# File 'lib/structured_data_to_sql/diagnostic.rb', line 15

def message
  @message
end

#sourcesObject (readonly)

Returns the value of attribute sources.



15
16
17
# File 'lib/structured_data_to_sql/diagnostic.rb', line 15

def sources
  @sources
end

#summaryObject (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_itemsObject (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

#titleObject (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(message)
  new(code: :generic, title: "Warning", message: 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_hObject



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: message
  }
end

#to_sObject



62
63
64
# File 'lib/structured_data_to_sql/diagnostic.rb', line 62

def to_s
  message
end