Class: IRWebmachine::TracedRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/irwebmachine/traced_request.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ IRWebmachine::TracedRequest

Returns an instance of IRWebmachine::TracedRequest.

Parameters:

  • app (Webmachine::Application)

    An instance of Webmachine::Application.



9
10
11
12
13
14
# File 'lib/irwebmachine/traced_request.rb', line 9

def initialize(app)
  @app = app
  @req = nil
  @res = nil
  @stack = IRWebmachine::Stack.new
end

Instance Method Details

#stackIRWebmachine::Stack

Returns an instance of Webmachine::Stack.

Returns:



20
21
22
# File 'lib/irwebmachine/traced_request.rb', line 20

def stack
  @stack
end

#to_aArray

Returns the arguments given to #trace or #trace!.

Examples:

@req.trace "GET", "/"
@req.trace *@req # replay request.

Returns:



51
52
53
# File 'lib/irwebmachine/traced_request.rb', line 51

def to_a
  [@req.method, @req.uri.path, @req.query, @req.headers, @req.body]
end

#trace(*args) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/irwebmachine/traced_request.rb', line 24

def trace(*args)
  trace!(*args)
  while frame = @stack.tracer.continue
    @stack << frame
  end
  @res
end

#trace!(type, path, params = {}, headers = {}, body = "") ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/irwebmachine/traced_request.rb', line 32

def trace!(type, path, params = {}, headers = {}, body = "")
  uri = URI::HTTP.build(host: "localhost", path: path)
  uri.query_params.merge!(params)
  @req = Webmachine::Request.new type.upcase, uri, headers, body
  @res = Webmachine::Response.new
  @stack.tracer.trace do
    @app.dispatcher.dispatch @req, @res
  end
  @res
end