Class: Appetizer::Rack::Splash

Inherits:
Object
  • Object
show all
Defined in:
lib/appetizer/rack/splash.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root = "public", glob = "**/*", &notfound) ⇒ Splash

Returns a new instance of Splash.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/appetizer/rack/splash.rb', line 4

def initialize root = "public", glob = "**/*", &notfound
  notfound ||= lambda { |env|
    [404, { "Content-Type" => "text/plain" }, []]
  }

  urls = Dir[File.join root, glob].sort.
    select { |f| File.file? f }.
    map    { |f| f[root.length..-1] }

  @static = ::Rack::Static.new notfound, root: root, urls: urls
end

Class Method Details

.call(env) ⇒ Object



24
25
26
# File 'lib/appetizer/rack/splash.rb', line 24

def self.call env
  new.call env
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/appetizer/rack/splash.rb', line 16

def call env
  if env["PATH_INFO"] == "/"
    env["PATH_INFO"] = "/index.html"
  end

  @static.call env
end