Class: Morpheus::Client::UncachedRequestFormatter

Inherits:
RequestFormatter show all
Defined in:
lib/morpheus/client/uncached_request_formatter.rb

Constant Summary

Constants inherited from RequestFormatter

RequestFormatter::CYAN, RequestFormatter::GREEN, RequestFormatter::MAGENTA, RequestFormatter::RED, RequestFormatter::YELLOW

Instance Attribute Summary

Attributes inherited from RequestFormatter

#event, #subscriber

Instance Method Summary collapse

Methods inherited from RequestFormatter

call, #color, #formatted_payload, #initialize, #odd?, #payload, #request_color

Constructor Details

This class inherits a constructor from Morpheus::Client::RequestFormatter

Instance Method Details

#callObject



5
6
7
# File 'lib/morpheus/client/uncached_request_formatter.rb', line 5

def call
  "#{request_statement} #{response_statement} #{payload}"
end

#durationObject



25
26
27
28
# File 'lib/morpheus/client/uncached_request_formatter.rb', line 25

def duration
  value = response.time * 1000
  "#{value}ms"
end

#request_statementObject



9
10
11
12
13
14
# File 'lib/morpheus/client/uncached_request_formatter.rb', line 9

def request_statement
  klass     = event.payload[:class]
  method    = event.payload[:method].to_s.upcase
  statement = "#{klass} #{method} (#{duration})"
  color(statement, request_color, true)
end

#responseObject



21
22
23
# File 'lib/morpheus/client/uncached_request_formatter.rb', line 21

def response
  event.payload[:response]
end

#response_colorObject



30
31
32
33
34
35
36
# File 'lib/morpheus/client/uncached_request_formatter.rb', line 30

def response_color
  case response.code
  when 200..299 then GREEN
  when 400..599 then RED
  else               YELLOW
  end
end

#response_statementObject



16
17
18
19
# File 'lib/morpheus/client/uncached_request_formatter.rb', line 16

def response_statement
  statement = "[#{response.code}]"
  color(statement, response_color, true)
end