Class: NetObserver::LastRequest

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/net_observer/last_request.rb

Overview

Logger class

It can be used to pass network communication into logger. It report requests and success response as info and failed one as warn message.

Examples:

Set simple logging to console

NetObserver::Logger.new Logger.new STDOUT

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#last_requestObject (readonly)

Returns the value of attribute last_request



13
14
15
# File 'lib/net_observer/last_request.rb', line 13

def last_request
  @last_request
end

Instance Method Details

#disableObject



21
22
23
24
# File 'lib/net_observer/last_request.rb', line 21

def disable
	@last_request = nil
	Base.instance.delete_observer(self)
end

#enableObject

register logger to receiving infos about network communication @param(Logger) logger which recieve informations about communication



16
17
18
19
# File 'lib/net_observer/last_request.rb', line 16

def enable
	@last_request = nil
	Base.instance.add_observer(self)
end

#update(type, request, body, connection) ⇒ Object

methods to receive information about connection. Needed to allow itself to register agains Base

See Also:

  • for parameters details


27
28
29
30
31
32
33
34
# File 'lib/net_observer/last_request.rb', line 27

def update(type, request, body, connection)
	case type
	when :response
		return #don't care
	when :request
		@last_request = { :connection => connection, :request => request, :body => (request.body || body)}
	end
end