Class: Herb::Warnings::Warning

Inherits:
Object
  • Object
show all
Defined in:
lib/herb/warnings.rb

Overview

: type serialized_warning = { | type: String, | location: serialized_location?, | message: String | }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, location, message) ⇒ Warning

: (String, Location, String) -> void



17
18
19
20
21
# File 'lib/herb/warnings.rb', line 17

def initialize(type, location, message)
  @type = type
  @location = location
  @message = message
end

Instance Attribute Details

#locationObject (readonly)

: Location?



13
14
15
# File 'lib/herb/warnings.rb', line 13

def location
  @location
end

#messageObject (readonly)

: String



14
15
16
# File 'lib/herb/warnings.rb', line 14

def message
  @message
end

#typeObject (readonly)

: String



12
13
14
# File 'lib/herb/warnings.rb', line 12

def type
  @type
end

Instance Method Details

#class_nameObject

: () -> String



33
34
35
# File 'lib/herb/warnings.rb', line 33

def class_name
  self.class.name || "Warning"
end

#to_hashObject

: () -> serialized_warning



24
25
26
27
28
29
30
# File 'lib/herb/warnings.rb', line 24

def to_hash
  {
    type: type,
    location: location&.to_hash,
    message: message,
  }
end

#to_json(state = nil) ⇒ Object

: (?untyped) -> String



43
44
45
# File 'lib/herb/warnings.rb', line 43

def to_json(state = nil)
  to_hash.to_json(state)
end

#warning_nameObject

: () -> String



38
39
40
# File 'lib/herb/warnings.rb', line 38

def warning_name
  class_name.split("::").last || "Warning"
end