Class: Webmachine::Trace::ResourceProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/webmachine/trace/resource_proxy.rb

Overview

This class is injected into the decision FSM as a stand-in for the resource when tracing is enabled. It proxies all callbacks to the resource so that they get logged in the trace.

Constant Summary collapse

CALLBACK_REFERRERS =

Callback methods that can return data that refers to user-defined callbacks that are not in the canonical set, including body-producing or accepting methods, encoders and charsetters.

[:content_types_accepted, :content_types_provided,
:encodings_provided, :charsets_provided]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ ResourceProxy

Creates a Webmachine::Trace::ResourceProxy that decorates the passed Resource such that callbacks invoked by the Decision::FSM will be logged in the response's trace.


21
22
23
24
25
# File 'lib/webmachine/trace/resource_proxy.rb', line 21

def initialize(resource)
  @resource = resource
  @dynamic_callbacks = Module.new
  extend @dynamic_callbacks
end

Instance Attribute Details

#resourceWebmachine::Resource (readonly)

Returns the wrapped resource.

Returns:


8
9
10
# File 'lib/webmachine/trace/resource_proxy.rb', line 8

def resource
  @resource
end

Instance Method Details

#charset_nop(*args) ⇒ Object


34
35
36
# File 'lib/webmachine/trace/resource_proxy.rb', line 34

def charset_nop(*args)
  proxy_callback :charset_nop, *args
end

#finish_request(*args) ⇒ Object

Calls the resource's finish_request method and then sets the trace id header in the response.


40
41
42
43
44
# File 'lib/webmachine/trace/resource_proxy.rb', line 40

def finish_request(*args)
  proxy_callback :finish_request, *args
ensure
  resource.response.headers['X-Webmachine-Trace-Id'] = object_id.to_s
end