Class: Bcms::WebDAV::File

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

Overview

Inherits from Rack File in order to change where paths are looked up from, since the public path of CMS files is different that actual file path.

Instance Method Summary collapse

Constructor Details

#initialize(absolute_file_path) ⇒ File

This should be an absolute file path



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

def initialize(absolute_file_path)
  @path = absolute_file_path
end

Instance Method Details

#_call(env) ⇒ Object

Don’t look up from PATH, look up from passed in variable



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

def _call(env)
  Rails.logger.debug "Starting to serve file @ path #{@path}"

  # From here down is a copy&paste of Rack::File#_call
  begin
    if F.file?(@path) && F.readable?(@path)
      serving
    else
      raise Errno::EPERM
    end
  rescue SystemCallError
    not_found
  end
end