class HttpStub::Server::Stub::Response::Response

Constants

DEFAULT_ARGS

Attributes

blocks[R]
body[R]
delay_in_seconds[R]
headers[R]
status[R]

Public Class Methods

new(args) click to toggle source
# File lib/http_stub/server/stub/response/response.rb, line 14
def initialize(args)
  @original_args    = args
  resolved_args     = DEFAULT_ARGS.merge(args)
  @status           = resolved_args[:status]
  @body             = HttpStub::Server::Stub::Response::Body.create(resolved_args)
  @headers          = HttpStub::Server::Stub::Response::Headers.create(resolved_args[:headers], @body)
  @delay_in_seconds = resolved_args[:delay_in_seconds]
  @blocks           = HttpStub::Server::Stub::Response::Blocks.new(resolved_args[:blocks])
end

Public Instance Methods

serve_on(application) click to toggle source
# File lib/http_stub/server/stub/response/response.rb, line 28
def serve_on(application)
  sleep @delay_in_seconds
  @body.serve(application, self)
end
to_hash() click to toggle source
# File lib/http_stub/server/stub/response/response.rb, line 33
def to_hash
  {
    status:           @status,
    headers:          @headers,
    body:             @body,
    delay_in_seconds: @delay_in_seconds,
    blocks:           @blocks.to_array
  }
end
to_json(*args) click to toggle source
# File lib/http_stub/server/stub/response/response.rb, line 43
def to_json(*args)
  self.to_hash.to_json(*args)
end
with_values_from(request) click to toggle source
# File lib/http_stub/server/stub/response/response.rb, line 24
def with_values_from(request)
  self.class.new(@original_args.merge(blocks: []).deep_merge(@blocks.evaluate_with(request)))
end