Class: Rreplay::OutputBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/rreplay/replay_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(style: :json) ⇒ OutputBuilder

Returns a new instance of OutputBuilder.

Parameters:

  • style (Symbol) (defaults to: :json)

    :json or :string



64
65
66
67
68
69
70
71
# File 'lib/rreplay/replay_runner.rb', line 64

def initialize(style: :json)
  @builder = case style
             when :json
               method(:build_json)
             else
               method(:build_string)
             end
end

Instance Method Details

#call(record, result) ⇒ Object

Parameters:



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rreplay/replay_runner.rb', line 75

def call(record, result)
  response_hash = {
    status: result.response.code,
    headers: record['response']['headers'].reduce({}) do |acc, (key, _)|
      acc.merge({key => result.response[key]})
    end,
    body: Array(result.response.body).join(''),
  }

  @builder.call(record, result.response_time, response_hash)
end