Sha256: f6fec69378b9eb95db0e46dade31e63a4056c36534ae96eca0aa5690c2b5e449

Contents?: true

Size: 1018 Bytes

Versions: 1

Compression:

Stored size: 1018 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
          [ (BASEDIR/'proto'/'public'),
            Global.controllers.map{|c| c.trait[:public]},
            './public'
          ].flatten.select{|f| ::File.directory?(f.to_s)}.map{|f| ::File.expand_path(f)}
        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.1 lib/ramaze/dispatcher/file.rb