Module: Webmachine::Trace::FSM
- Included in:
- Decision::FSM
- Defined in:
- lib/webmachine/trace/fsm.rb
Overview
This module is injected into Decision::FSM when tracing is enabled for a resource, enabling the capturing of traces.
Instance Method Summary collapse
-
#initialize(_resource, _request, _response) ⇒ Object
Overrides the default resource accessor so that incoming callbacks are traced.
- #trace? ⇒ Boolean
-
#trace_decision(decision) ⇒ Object
Adds a decision to the trace.
-
#trace_request(request) ⇒ Object
Adds the request to the trace.
-
#trace_response(response) ⇒ Object
Adds the response to the trace and then commits the trace to separate storage which can be discovered by the debugger.
Instance Method Details
#initialize(_resource, _request, _response) ⇒ Object
Overrides the default resource accessor so that incoming callbacks are traced.
9 10 11 12 13 14 15 16 17 |
# File 'lib/webmachine/trace/fsm.rb', line 9 def initialize(_resource, _request, _response) if trace? class << self def resource @resource_proxy ||= ResourceProxy.new(@resource) end end end end |
#trace? ⇒ Boolean
19 20 21 |
# File 'lib/webmachine/trace/fsm.rb', line 19 def trace? Trace.trace?(@resource) end |
#trace_decision(decision) ⇒ Object
Adds a decision to the trace.
54 55 56 |
# File 'lib/webmachine/trace/fsm.rb', line 54 def trace_decision(decision) response.trace << {:type => :decision, :decision => decision} if trace? end |
#trace_request(request) ⇒ Object
Adds the request to the trace.
25 26 27 28 29 30 31 32 33 |
# File 'lib/webmachine/trace/fsm.rb', line 25 def trace_request(request) response.trace << { :type => :request, :method => request.method, :path => request.uri.request_uri.to_s, :headers => request.headers, :body => request.body.to_s } if trace? end |
#trace_response(response) ⇒ Object
Adds the response to the trace and then commits the trace to separate storage which can be discovered by the debugger.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/webmachine/trace/fsm.rb', line 38 def trace_response(response) response.trace << { :type => :response, :code => response.code.to_s, :headers => response.headers, :body => trace_response_body(response.body) } if trace? ensure Webmachine::Events.publish('wm.trace.record', { :trace_id => resource.object_id.to_s, :trace => response.trace }) if trace? end |