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.



23
24
25
26
27
# File 'lib/webmachine/trace/resource_proxy.rb', line 23

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

Instance Attribute Details

#resourceWebmachine::Resource (readonly)

Returns the wrapped resource.

Returns:



10
11
12
# File 'lib/webmachine/trace/resource_proxy.rb', line 10

def resource
  @resource
end

Instance Method Details

#charset_nop(*args) ⇒ Object



36
37
38
# File 'lib/webmachine/trace/resource_proxy.rb', line 36

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.



42
43
44
45
46
# File 'lib/webmachine/trace/resource_proxy.rb', line 42

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