Class: Yell::Formatter::Modifier

Inherits:
Object
  • Object
show all
Defined in:
lib/yell/formatter.rb

Overview

Message modifier class to allow different modifiers for different requirements.

Instance Method Summary collapse

Constructor Details

#initializeModifier

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( message )
  case
  when mod = @repository[message.class] || @repository[message.class.to_s]
    mod.call(message)
  when message.is_a?(Array)
    message.map { |m| call(m) }.join(" ")
  when message.is_a?(Hash)
    message.map { |k, v| "#{k}: #{v}" }.join(", ")
  when message.is_a?(Exception)
    backtrace = message.backtrace ? "\n\t#{message.backtrace.join("\n\t")}" : ""
    sprintf("%s: %s%s", message.class, message.message, backtrace)
  else
    message
  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