Class: Smith::Workflow::Graph::Diagnostic

Inherits:
Object
  • Object
show all
Defined in:
lib/smith/workflow/graph/diagnostic.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**attributes) ⇒ Diagnostic

Returns a new instance of Diagnostic.



11
12
13
14
15
16
17
18
19
20
# File 'lib/smith/workflow/graph/diagnostic.rb', line 11

def initialize(**attributes)
  @severity = attributes.fetch(:severity)
  @code = attributes.fetch(:code)
  @message = attributes.fetch(:message)
  @path = attributes[:path]
  @state = attributes[:state]
  @transition = attributes[:transition]
  @target = attributes[:target]
  @suggestion = attributes[:suggestion]
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



9
10
11
# File 'lib/smith/workflow/graph/diagnostic.rb', line 9

def code
  @code
end

#severityObject (readonly)

Returns the value of attribute severity.



9
10
11
# File 'lib/smith/workflow/graph/diagnostic.rb', line 9

def severity
  @severity
end

#stateObject (readonly)

Returns the value of attribute state.



9
10
11
# File 'lib/smith/workflow/graph/diagnostic.rb', line 9

def state
  @state
end

#suggestionObject (readonly)

Returns the value of attribute suggestion.



9
10
11
# File 'lib/smith/workflow/graph/diagnostic.rb', line 9

def suggestion
  @suggestion
end

#targetObject (readonly)

Returns the value of attribute target.



9
10
11
# File 'lib/smith/workflow/graph/diagnostic.rb', line 9

def target
  @target
end

#transitionObject (readonly)

Returns the value of attribute transition.



9
10
11
# File 'lib/smith/workflow/graph/diagnostic.rb', line 9

def transition
  @transition
end

Instance Method Details

#messageObject



22
23
24
25
26
27
28
29
30
# File 'lib/smith/workflow/graph/diagnostic.rb', line 22

def message
  return @message unless @path
  return @rendered_message if defined?(@rendered_message)

  @rendered_message = String.new.tap do |rendered|
    @path.each_label { |label| rendered << "Nested workflow #{label}: " }
    rendered << @message
  end.freeze
end

#nested(label:, code:, transition:, target:) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/smith/workflow/graph/diagnostic.rb', line 32

def nested(label:, code:, transition:, target:)
  self.class.new(
    severity: severity,
    code: code,
    message: @message,
    path: DiagnosticPath.new(label:, tail: @path),
    state: state,
    transition: transition,
    target: target,
    suggestion: suggestion
  )
end

#to_hObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/smith/workflow/graph/diagnostic.rb', line 45

def to_h
  {
    severity: severity,
    code: code,
    message: message,
    state: state,
    transition: transition,
    target: target,
    suggestion: suggestion
  }.compact
end