Class: Tzispa::Helpers::Services::SendFile

Inherits:
Object
  • Object
show all
Defined in:
lib/tzispa/helpers/services/send_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, path, opts) ⇒ SendFile

Returns a new instance of SendFile.



12
13
14
15
16
# File 'lib/tzispa/helpers/services/send_file.rb', line 12

def initialize(response, path, opts)
  @response = response
  @opts = opts
  @path = path
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



10
11
12
# File 'lib/tzispa/helpers/services/send_file.rb', line 10

def opts
  @opts
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/tzispa/helpers/services/send_file.rb', line 10

def path
  @path
end

#responseObject (readonly)

Returns the value of attribute response.



10
11
12
# File 'lib/tzispa/helpers/services/send_file.rb', line 10

def response
  @response
end

Instance Method Details

#content_disposition(filename = nil, disposition = 'attachment') ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/tzispa/helpers/services/send_file.rb', line 18

def content_disposition(filename = nil, disposition = 'attachment')
  disposition = String.new << disposition.to_s
  if filename
    escaped = URI.escape(filename)
    disposition << "; filename=\"#{escaped}\""
    disposition << "; filename*=UTF-8''#{escaped}"
  end
  response['Content-Disposition'] = disposition
end

#send(result) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/tzispa/helpers/services/send_file.rb', line 28

def send(result)
  prepare
  response.status = result[0]
  if response.status.between? 200, 299
    headers_set result[1]
    response.body = result[2]
  end
  response
end