Class: Herb::Warnings::Warning

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

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

Parameters:



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

#locationLocation? (readonly)

: Location?

Returns:



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

def location
  @location
end

#messageString (readonly)

: String

Returns:

  • (String)


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

def message
  @message
end

#typeString (readonly)

: String

Returns:

  • (String)


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

def type
  @type
end

Instance Method Details

#class_nameString

: () -> String

Returns:

  • (String)


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

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

#to_hashserialized_warning

: () -> serialized_warning

Returns:

  • (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) ⇒ String

: (?untyped) -> String

Parameters:

  • (Object)

Returns:

  • (String)


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

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

#warning_nameString

: () -> String

Returns:

  • (String)


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

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