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.
128 129 130 |
# File 'lib/yell/formatter.rb', line 128 def initialize @repository = {} end |
Instance Method Details
#call(message) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/yell/formatter.rb', line 136 def call( ) case when mod = @repository[.class] || @repository[.class.to_s] mod.call() when .is_a?(Array) .map { |m| call(m) }.join(" ") 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
132 133 134 |
# File 'lib/yell/formatter.rb', line 132 def set( key, &block ) @repository.merge!(key => block) end |