Class: Nyanko::Logger::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/nyanko/logger.rb

Constant Summary collapse

PREFIX =
"  [Nyanko]"

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Message

Returns a new instance of Message.



24
25
26
# File 'lib/nyanko/logger.rb', line 24

def initialize(object)
  @object = object
end

Instance Method Details

#backtraceObject



54
55
56
57
58
59
60
# File 'lib/nyanko/logger.rb', line 54

def backtrace
  if has_backtrace?
    lines = @object.backtrace[0...Config.backtrace_limit]
    str   = lines.map {|line| "  #{line}" }.join("\n")
    "\n#{str}"
  end
end

#bodyObject



44
45
46
47
48
# File 'lib/nyanko/logger.rb', line 44

def body
  unless @object.message.empty?
    " - #@object"
  end
end

#contentObject



36
37
38
39
40
41
42
# File 'lib/nyanko/logger.rb', line 36

def content
  if @object.is_a?(Exception)
    "#{klass}#{body}#{backtrace}"
  else
    @object.to_s
  end
end

#has_backtrace?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/nyanko/logger.rb', line 62

def has_backtrace?
  @object.backtrace
end

#klassObject



50
51
52
# File 'lib/nyanko/logger.rb', line 50

def klass
  @object.class
end

#prefix(str) ⇒ Object



32
33
34
# File 'lib/nyanko/logger.rb', line 32

def prefix(str)
  str.split("\n").map {|line| "#{PREFIX} #{line}" }.join("\n")
end

#to_sObject



28
29
30
# File 'lib/nyanko/logger.rb', line 28

def to_s
  prefix(content)
end