Class: YardJunk::Logger::Message
- Inherits:
-
Object
- Object
- YardJunk::Logger::Message
show all
- Includes:
- Spellcheck
- Defined in:
- lib/yard-junk/logger/message.rb
Direct Known Subclasses
CircularReference, DuplicateParam, InvalidDirectiveFormat, InvalidFileLink, InvalidLink, InvalidTagFormat, MacroAttachError, MacroNameError, MissingParamName, RedundantBraces, SyntaxError, Undocumentable, UnknownDirective, UnknownNamespace, UnknownParam, UnknownTag
Constant Summary
collapse
- DEFAULT_FORMAT =
'%{file}:%{line}: [%{type}] %{message}'
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Spellcheck
#spell_check
Constructor Details
#initialize(message:, severity: :warn, code_object: nil, file: nil, line: nil, **extra) ⇒ Message
Returns a new instance of Message.
10
11
12
13
14
15
16
17
|
# File 'lib/yard-junk/logger/message.rb', line 10
def initialize(message:, severity: :warn, code_object: nil, file: nil, line: nil, **)
@message = message.gsub(/\s{2,}/, ' ')
@file = file
@line = line&.to_i
@code_object = code_object
@severity = severity
@extra =
end
|
Instance Attribute Details
Returns the value of attribute extra.
8
9
10
|
# File 'lib/yard-junk/logger/message.rb', line 8
def
@extra
end
|
#file ⇒ Object
Returns the value of attribute file.
8
9
10
|
# File 'lib/yard-junk/logger/message.rb', line 8
def file
@file
end
|
#line ⇒ Object
Returns the value of attribute line.
8
9
10
|
# File 'lib/yard-junk/logger/message.rb', line 8
def line
@line
end
|
#message ⇒ Object
Returns the value of attribute message.
8
9
10
|
# File 'lib/yard-junk/logger/message.rb', line 8
def message
@message
end
|
#severity ⇒ Object
Returns the value of attribute severity.
8
9
10
|
# File 'lib/yard-junk/logger/message.rb', line 8
def severity
@severity
end
|
Class Method Details
.pattern(regexp) ⇒ Object
53
54
55
56
|
# File 'lib/yard-junk/logger/message.rb', line 53
def pattern(regexp)
@pattern = regexp
Message.registry << self
end
|
.registry ⇒ Object
49
50
51
|
# File 'lib/yard-junk/logger/message.rb', line 49
def registry
@registry ||= []
end
|
.search_up(pattern) ⇒ Object
58
59
60
|
# File 'lib/yard-junk/logger/message.rb', line 58
def search_up(pattern)
@search_up = pattern
end
|
.try_parse(line, **context) ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/yard-junk/logger/message.rb', line 62
def try_parse(line, **context)
@pattern or fail StandardError, "Pattern is not defined for #{self}"
match = @pattern.match(line) or return nil
data = context.compact
.merge(match.names.map(&:to_sym).zip(match.captures).to_h.compact)
data = guard_line(data)
new(**data)
end
|
.type ⇒ Object
71
72
73
|
# File 'lib/yard-junk/logger/message.rb', line 71
def type
!name || name.end_with?('::Message') ? 'UnknownError' : name.sub(/^.+::/, '')
end
|
.valid_type?(type) ⇒ Boolean
75
76
77
|
# File 'lib/yard-junk/logger/message.rb', line 75
def valid_type?(type)
type == 'UnknownError' || registry.any? { |m| m.type == type }
end
|
Instance Method Details
#==(other) ⇒ Object
32
33
34
|
# File 'lib/yard-junk/logger/message.rb', line 32
def ==(other)
other.is_a?(self.class) && to_h == other.to_h
end
|
#to_h ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'lib/yard-junk/logger/message.rb', line 23
def to_h
{
type: type,
message: message,
file: file,
line: line&.to_i || 1
}.merge()
end
|
#to_s(format = DEFAULT_FORMAT) ⇒ Object
38
39
40
|
# File 'lib/yard-junk/logger/message.rb', line 38
def to_s(format = DEFAULT_FORMAT)
format % to_h
end
|
#type ⇒ Object
42
43
44
|
# File 'lib/yard-junk/logger/message.rb', line 42
def type
self.class.type
end
|