Module: Webmachine::Trace::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

Instance Method Details

#resourceObject

Overrides the default resource accessor so that incoming callbacks are traced.


44
45
46
# File 'lib/webmachine/trace/fsm.rb', line 44

def resource
  @resource_proxy ||= ResourceProxy.new(@resource)
end

#trace_decision(decision) ⇒ Object

Adds a decision to the trace.

Parameters:

  • decision (Symbol)

    the decision being processed


38
39
40
# File 'lib/webmachine/trace/fsm.rb', line 38

def trace_decision(decision)
  response.trace << {:type => :decision, :decision => decision}
end

#trace_request(request) ⇒ Object

Adds the request to the trace.

Parameters:


9
10
11
12
13
14
15
16
17
# File 'lib/webmachine/trace/fsm.rb', line 9

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
  }
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.

Parameters:


22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/webmachine/trace/fsm.rb', line 22

def trace_response(response)
  response.trace << {
    :type => :response,
    :code => response.code.to_s,
    :headers => response.headers,
    :body => trace_response_body(response.body)
  }
ensure
  Webmachine::Events.publish('wm.trace.record', {
    :trace_id => resource.object_id.to_s,
    :trace => response.trace
  })
end