Sha256: bda62bf32e826776ab2b291f60f917cb2cfc25d4abcdd07887d062a436e55ad1

Contents?: true

Size: 735 Bytes

Versions: 2

Compression:

Stored size: 735 Bytes

Contents

# frozen_string_literal: true

require "rack/file"

module Hanami
  class Action
    module Rack
      # File to be sent
      #
      # @since 0.4.3
      # @api private
      #
      # @see Hanami::Action::Rack#send_file
      class File
        # @param path [String,Pathname] file path
        #
        # @since 0.4.3
        # @api private
        def initialize(path, root)
          @file = ::Rack::File.new(root.to_s)
          @path = path.to_s
        end

        # @since 0.4.3
        # @api private
        def call(env)
          env = env.dup
          env[Action::PATH_INFO] = @path

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

Version data entries

2 entries across 2 versions & 1 rubygems

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