Class: HttpStub::Server::Stub::Response::File

Inherits:
Base
  • Object
show all
Defined in:
lib/http_stub/server/stub/response/file.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#delay_in_seconds, #headers, #status

Instance Method Summary collapse

Methods inherited from Base

add_default_headers, merge_defaults, #to_json, #type

Constructor Details

#initialize(args) ⇒ File

Returns a new instance of File.



12
13
14
15
16
# File 'lib/http_stub/server/stub/response/file.rb', line 12

def initialize(args)
  @file = args["body"][:tempfile]
  @uri  = "file://#{@file.path}"
  super
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



10
11
12
# File 'lib/http_stub/server/stub/response/file.rb', line 10

def uri
  @uri
end

Instance Method Details

#serve_on(application) ⇒ Object



22
23
24
25
# File 'lib/http_stub/server/stub/response/file.rb', line 22

def serve_on(application)
  application.send_file(@file.path, send_options)
  @status = application.response.status
end

#to_hashObject



27
28
29
# File 'lib/http_stub/server/stub/response/file.rb', line 27

def to_hash
  super.merge(file_uri: @uri)
end

#with_values_from(request) ⇒ Object



18
19
20
# File 'lib/http_stub/server/stub/response/file.rb', line 18

def with_values_from(request)
  self.class.new(@original_args.merge("headers" => @headers.with_values_from(request)))
end