Sha256: 4f03e490470f6795969040b046bee6c0fff13ccb3314bc6c1af7d571b979f070

Contents?: true

Size: 870 Bytes

Versions: 1

Compression:

Stored size: 870 Bytes

Contents

#          Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.

module Ramaze
  module Dispatcher
    class File
      class << self
        def process(path)
          return unless file = open_file(path)
          Dispatcher.build_response(file, Ramaze::STATUS_CODE['OK'])
        end

        def lookup_paths
          [ Global.public_proto, Global.public_root ].flatten
        end

        def open_file(path)
          paths = lookup_paths.map{|pa| pa/path}
          file = paths.find{|way| ::File.file?(way)}

          if file
            response = Response.current
            response['Content-Type'] = Tool::MIME.type_for(file)
            Inform.debug("Serving static: #{file}")
            ::File.open(file, 'rb')
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ramaze-0.1.2 lib/ramaze/dispatcher/file.rb