Class: DAV4Rack::File

Inherits:
Rack::File
  • Object
show all
Defined in:
lib/dav4rack/file.rb

Overview

DAV4Rack::File simply allows us to use Rack::File but with the specific location we deem appropriate

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ File

Returns a new instance of File.



13
14
15
# File 'lib/dav4rack/file.rb', line 13

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject Also known as: to_path

Returns the value of attribute path.



9
10
11
# File 'lib/dav4rack/file.rb', line 9

def path
  @path
end

Instance Method Details

#_call(env) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dav4rack/file.rb', line 17

def _call(env)
  begin
    if F.file?(@path) && F.readable?(@path)
      serving(env)
    else
      raise Errno::EPERM
    end
  rescue SystemCallError
    not_found
  end
end

#not_foundObject



29
30
31
32
33
34
35
# File 'lib/dav4rack/file.rb', line 29

def not_found
  body = "File not found: #{Rack::Utils.unescape(env["PATH_INFO"])}\n"
  [404, {"Content-Type" => "text/plain",
     "Content-Length" => body.size.to_s,
     "X-Cascade" => "pass"},
   [body]]
end