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.
129 130 131 |
# File 'lib/yell/formatter.rb', line 129 def initialize @repository = {} end |
Instance Method Details
#call(message) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/yell/formatter.rb', line 137 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
133 134 135 |
# File 'lib/yell/formatter.rb', line 133 def set( key, &block ) @repository.merge!(key => block) end |