Class: YardJunk::Logger::Message
- Inherits:
-
Object
- Object
- YardJunk::Logger::Message
- Defined in:
- lib/yard-junk/logger/message.rb
Direct Known Subclasses
CircularReference, DuplicateParam, InvalidDirectiveFormat, InvalidLink, InvalidTagFormat, MacroAttachError, MacroNameError, MissingParamName, RedundantBraces, SyntaxError, Undocumentable, UnknownDirective, UnknownNamespace, UnknownParam, UnknownTag
Defined Under Namespace
Classes: SpellChecker, SpellFinder
Constant Summary collapse
- DEFAULT_FORMAT =
'%{file}:%{line}: [%{type}] %{message}'
Instance Attribute Summary collapse
-
#extra ⇒ Object
readonly
Returns the value of attribute extra.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#severity ⇒ Object
readonly
Returns the value of attribute severity.
Class Method Summary collapse
- .pattern(regexp) ⇒ Object
- .registry ⇒ Object
-
.search_up(pattern) ⇒ Object
rubocop:disable Style/TrivialAccessors.
- .try_parse(line, **context) ⇒ Object
- .type ⇒ Object
- .valid_type?(type) ⇒ Boolean
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(message:, severity: :warn, code_object: nil, file: nil, line: nil, **extra) ⇒ Message
constructor
A new instance of Message.
- #to_h ⇒ Object
- #to_s(format = DEFAULT_FORMAT) ⇒ Object
- #type ⇒ Object
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, **extra) @message = .gsub(/\s{2,}/, ' ') @file = file @line = line && line.to_i @code_object = code_object @severity = severity @extra = extra end |
Instance Attribute Details
#extra ⇒ Object (readonly)
Returns the value of attribute extra.
8 9 10 |
# File 'lib/yard-junk/logger/message.rb', line 8 def extra @extra end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
8 9 10 |
# File 'lib/yard-junk/logger/message.rb', line 8 def file @file end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
8 9 10 |
# File 'lib/yard-junk/logger/message.rb', line 8 def line @line end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
8 9 10 |
# File 'lib/yard-junk/logger/message.rb', line 8 def @message end |
#severity ⇒ Object (readonly)
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
89 90 91 92 |
# File 'lib/yard-junk/logger/message.rb', line 89 def pattern(regexp) @pattern = regexp Message.registry << self end |
.registry ⇒ Object
85 86 87 |
# File 'lib/yard-junk/logger/message.rb', line 85 def registry @registry ||= [] end |
.search_up(pattern) ⇒ Object
rubocop:disable Style/TrivialAccessors
94 95 96 |
# File 'lib/yard-junk/logger/message.rb', line 94 def search_up(pattern) # rubocop:disable Style/TrivialAccessors @search_up = pattern end |
.try_parse(line, **context) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/yard-junk/logger/message.rb', line 98 def try_parse(line, **context) @pattern or fail StandardError, "Pattern is not defined for #{self}" match = @pattern.match(line) or return nil data = context.reject { |_, v| v.nil? } .merge(match.names.map(&:to_sym).zip(match.captures).to_h.reject { |_, v| v.nil? }) data = guard_line(data) new(**data) end |
.type ⇒ Object
107 108 109 |
# File 'lib/yard-junk/logger/message.rb', line 107 def type !name || name.end_with?('::Message') ? 'UnknownError' : name.sub(/^.+::/, '') end |
.valid_type?(type) ⇒ Boolean
111 112 113 |
# File 'lib/yard-junk/logger/message.rb', line 111 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: , file: file, line: (line && line.to_i) || 1 }.merge(extra) 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 |