Class: Hanami::Action::Rack::File Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/action/rack/file.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

File to be sent

See Also:

  • #send_file

Since:

  • 0.4.3

Constant Summary collapse

PATH_INFO =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The key that returns path info from the Rack env

Since:

  • 1.0.0

"PATH_INFO".freeze

Instance Method Summary collapse

Constructor Details

#initialize(path, root) ⇒ File

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of File.

Parameters:

  • path (String, Pathname)

    file path

Since:

  • 0.4.3



23
24
25
26
# File 'lib/hanami/action/rack/file.rb', line 23

def initialize(path, root)
  @file = ::Rack::File.new(root.to_s)
  @path = path.to_s
end

Instance Method Details

#call(env) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.4.3



30
31
32
33
34
35
36
37
# File 'lib/hanami/action/rack/file.rb', line 30

def call(env)
  env = env.dup
  env[PATH_INFO] = @path

  @file.get(env)
rescue Errno::ENOENT
  [404, {}, nil]
end