Class: GraphQL::Doctor::Diagnostic

Inherits:
Struct
  • Object
show all
Defined in:
lib/graphql/doctor/diagnostic.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(suggestions: [], notes: [], **attributes) ⇒ Diagnostic

Returns a new instance of Diagnostic.



22
23
24
25
# File 'lib/graphql/doctor/diagnostic.rb', line 22

def initialize(suggestions: [], notes: [], **attributes)
  super(suggestions: suggestions.freeze, notes: notes.freeze, **attributes)
  freeze
end

Instance Attribute Details

#codeObject

Returns the value of attribute code

Returns:

  • (Object)

    the current value of code



18
19
20
# File 'lib/graphql/doctor/diagnostic.rb', line 18

def code
  @code
end

#fingerprintObject

Returns the value of attribute fingerprint

Returns:

  • (Object)

    the current value of fingerprint



18
19
20
# File 'lib/graphql/doctor/diagnostic.rb', line 18

def fingerprint
  @fingerprint
end

#locationObject

Returns the value of attribute location

Returns:

  • (Object)

    the current value of location



18
19
20
# File 'lib/graphql/doctor/diagnostic.rb', line 18

def location
  @location
end

#messageObject

Returns the value of attribute message

Returns:

  • (Object)

    the current value of message



18
19
20
# File 'lib/graphql/doctor/diagnostic.rb', line 18

def message
  @message
end

#notesObject

Returns the value of attribute notes

Returns:

  • (Object)

    the current value of notes



18
19
20
# File 'lib/graphql/doctor/diagnostic.rb', line 18

def notes
  @notes
end

#severityObject

Returns the value of attribute severity

Returns:

  • (Object)

    the current value of severity



18
19
20
# File 'lib/graphql/doctor/diagnostic.rb', line 18

def severity
  @severity
end

#suggestionsObject

Returns the value of attribute suggestions

Returns:

  • (Object)

    the current value of suggestions



18
19
20
# File 'lib/graphql/doctor/diagnostic.rb', line 18

def suggestions
  @suggestions
end

Class Method Details

.from_h(hash) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/graphql/doctor/diagnostic.rb', line 27

def self.from_h(hash)
  values = hash.transform_keys(&:to_sym)
  values[:location] = Location.from_h(values[:location]) if values[:location]
  values[:suggestions] = Array(values[:suggestions]).map do |suggestion|
    suggestion = suggestion.transform_keys(&:to_sym)
    suggestion[:location] = Location.from_h(suggestion[:location]) if suggestion[:location]
    Suggestion.new(**suggestion)
  end
  new(**values)
end

Instance Method Details

#to_hObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/graphql/doctor/diagnostic.rb', line 38

def to_h
  {
    code: code,
    severity: severity.to_s,
    message: message,
    location: location&.to_h,
    suggestions: suggestions.map(&:to_h),
    notes: notes,
    fingerprint: fingerprint
  }.compact
end