Class: WarningSigns::MessageFormatter::Base
- Inherits:
-
Object
- Object
- WarningSigns::MessageFormatter::Base
- Includes:
- CallerHelper
- Defined in:
- lib/warning_signs/message_formatter/base.rb
Instance Attribute Summary collapse
-
#backtrace_lines ⇒ Object
readonly
Returns the value of attribute backtrace_lines.
-
#behaviors ⇒ Object
readonly
Returns the value of attribute behaviors.
-
#environments ⇒ Object
readonly
Returns the value of attribute environments.
-
#filter_backtraces ⇒ Object
readonly
Returns the value of attribute filter_backtraces.
Class Method Summary collapse
Instance Method Summary collapse
- #filtered_backtrace(backtrace) ⇒ Object
- #filtered_backtrace_lines(backtrace) ⇒ Object
- #format_message(message, backtrace) ⇒ Object
-
#initialize(backtrace_lines: 0, behaviors: {}, environments: {}, filter_backtraces: "yes") ⇒ Base
constructor
A new instance of Base.
Methods included from CallerHelper
#caller_filtered, #ignore_line
Constructor Details
#initialize(backtrace_lines: 0, behaviors: {}, environments: {}, filter_backtraces: "yes") ⇒ Base
Returns a new instance of Base.
14 15 16 17 18 19 |
# File 'lib/warning_signs/message_formatter/base.rb', line 14 def initialize(backtrace_lines: 0, behaviors: {}, environments: {}, filter_backtraces: "yes") @backtrace_lines = backtrace_lines @behaviors = OnlyExcept.new(**behaviors.symbolize_keys) @environments = OnlyExcept.new(**environments.symbolize_keys) @filter_backtraces = filter_backtraces.to_s.downcase.inquiry end |
Instance Attribute Details
#backtrace_lines ⇒ Object (readonly)
Returns the value of attribute backtrace_lines.
5 6 7 |
# File 'lib/warning_signs/message_formatter/base.rb', line 5 def backtrace_lines @backtrace_lines end |
#behaviors ⇒ Object (readonly)
Returns the value of attribute behaviors.
5 6 7 |
# File 'lib/warning_signs/message_formatter/base.rb', line 5 def behaviors @behaviors end |
#environments ⇒ Object (readonly)
Returns the value of attribute environments.
5 6 7 |
# File 'lib/warning_signs/message_formatter/base.rb', line 5 def environments @environments end |
#filter_backtraces ⇒ Object (readonly)
Returns the value of attribute filter_backtraces.
5 6 7 |
# File 'lib/warning_signs/message_formatter/base.rb', line 5 def filter_backtraces @filter_backtraces end |
Class Method Details
.for(**args) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/warning_signs/message_formatter/base.rb', line 7 def self.for(**args) args = args.symbolize_keys type = args.delete(:format) || "text" class_name = "WarningSigns::MessageFormatter::#{type.classify}" class_name.constantize.new(**args) end |
Instance Method Details
#filtered_backtrace(backtrace) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/warning_signs/message_formatter/base.rb', line 25 def filtered_backtrace(backtrace) return [] if backtrace.nil? result = backtrace.reject do |location| ignore_line(location.to_s, filter_backtraces: filter_backtraces) end result.empty? ? backtrace : result end |
#filtered_backtrace_lines(backtrace) ⇒ Object
33 34 35 36 |
# File 'lib/warning_signs/message_formatter/base.rb', line 33 def filtered_backtrace_lines(backtrace) return [] if backtrace_lines.zero? filtered_backtrace(backtrace)[1..backtrace_lines] || [] end |
#format_message(message, backtrace) ⇒ Object
21 22 23 |
# File 'lib/warning_signs/message_formatter/base.rb', line 21 def (, backtrace) raise NotImplementedError end |