Class: BodyLogger

Inherits:
Faraday::Response::Logger
  • Object
show all
Defined in:
lib/code42.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



71
72
73
74
# File 'lib/code42.rb', line 71

def call(env)
  debug('response') { dump_body(env[:body]) }
  super
end

#dump_body(body) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/code42.rb', line 81

def dump_body(body)
  if body.respond_to?(:to_str)
    body.to_str
  else
    pretty_inspect(body)
  end
end

#on_complete(env) ⇒ Object



76
77
78
79
# File 'lib/code42.rb', line 76

def on_complete(env)
  debug('response') { dump_body(env[:body]) }
  super
end

#pretty_inspect(body) ⇒ Object



89
90
91
92
# File 'lib/code42.rb', line 89

def pretty_inspect(body)
  require 'pp' unless body.respond_to?(:pretty_inspect)
  body.pretty_inspect
end