class Artifact::Static

Constants

DEFAULTS
NOT_FOUND
SUFFIXES

Public Class Methods

new(options = {}) click to toggle source
# File lib/artifact/static.rb, line 15
def initialize(options = {})
  not_found  = options.delete(:not_found) || NOT_FOUND
  text       = IO.read(not_found) if File.exist?(not_found)

  @suffixes  = options.delete(:suffixes)  || SUFFIXES

  @not_found = [404, {"Content-Type" => 'text/html'}, [text]]
  @static    = ::Rack::Static.new( lambda { [404, {}, []] }, DEFAULTS.merge(options))
end

Public Instance Methods

call(env) click to toggle source
# File lib/artifact/static.rb, line 25
def call(env)
  # resp = Rack::Head.call(env)
  # return resp if resp[0] != 404

  found = nil
  @suffixes.each do |suffix|
   url = env['PATH_INFO'] + suffix
   resp = @static.call(env.merge({'PATH_INFO' => url}))
   break if resp[0] != 404 && found = resp
  end

  found or @not_found
end