Sha256: 7758ce1b833802125794334cdb30655d9856089e9e82b1e6a95499eba3b5b10c

Contents?: true

Size: 810 Bytes

Versions: 1

Compression:

Stored size: 810 Bytes

Contents

require 'rack/file'

module Hanami
  module Action
    module Rack
      # File to be sent
      #
      # @since 0.4.3
      # @api private
      #
      # @see Hanami::Action::Rack#send_file
      class File

        # The key that returns path info from the Rack env
        #
        # @since 1.0.0.beta1
        # @api private
        PATH_INFO = "PATH_INFO".freeze

        # @param path [String,Pathname] file path
        #
        # @since 0.4.3
        # @api private
        def initialize(path, root)
          @file = ::Rack::File.new(root)
          @path = path
        end

        # @since 0.4.3
        # @api private
        def call(env)
          env[PATH_INFO] = @path
          @file.get(env)
        rescue Errno::ENOENT
          [404, {}, nil]
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hanami-controller-1.0.0.beta1 lib/hanami/action/rack/file.rb