Class: Mimic::FakeHost::RequestEcho

Inherits:
Object
  • Object
show all
Defined in:
lib/mimic/fake_host.rb

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ RequestEcho

Returns a new instance of RequestEcho.



106
107
108
# File 'lib/mimic/fake_host.rb', line 106

def initialize(request)
  @request = request
end

Instance Method Details

#response_as(format) ⇒ Object



110
111
112
113
114
115
116
117
118
# File 'lib/mimic/fake_host.rb', line 110

def response_as(format)
  content_type = case format
  when :json, :plist
    "application/#{format.to_s.downcase}"
  else
    "text/plain"
  end
  [200, {"Content-Type" => content_type}, to_s(format)]
end

#to_hashObject



131
132
133
134
135
136
137
# File 'lib/mimic/fake_host.rb', line 131

def to_hash
  {"echo" => {
    "params" => @request.params,
    "env"    => env_without_rack_and_async_env,
    "body"   => @request.body.read
  }}
end

#to_s(format) ⇒ Object



120
121
122
123
124
125
126
127
128
129
# File 'lib/mimic/fake_host.rb', line 120

def to_s(format)
  case format
    when :json
      to_hash.to_json
    when :plist
      to_hash.to_plist
    when :text
      to_hash.inspect
  end
end