Class: Yell::Formatter::Modifier
- Inherits:
-
Object
- Object
- Yell::Formatter::Modifier
- Defined in:
- lib/yell/formatter.rb
Overview
Message modifier class to allow different modifiers for different requirements.
Instance Method Summary collapse
- #call(message) ⇒ Object
-
#initialize ⇒ Modifier
constructor
A new instance of Modifier.
- #set(key, &block) ⇒ Object
Constructor Details
#initialize ⇒ Modifier
Returns a new instance of Modifier.
108 109 110 |
# File 'lib/yell/formatter.rb', line 108 def initialize @repository = {} end |
Instance Method Details
#call(message) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/yell/formatter.rb', line 116 def call( ) case when mod = @repository[.class] || @repository[.class.to_s] mod.call() when .is_a?(Hash) .map { |k,v| "#{k}: #{v}" }.join(", ") when .is_a?(Exception) backtrace = .backtrace ? "\n\t#{.backtrace.join("\n\t")}" : "" sprintf("%s: %s%s", .class, ., backtrace) else end end |
#set(key, &block) ⇒ Object
112 113 114 |
# File 'lib/yell/formatter.rb', line 112 def set( key, &block ) @repository.merge!(key => block) end |