Class: Vienna::Static

Inherits:
Object
  • Object
show all
Defined in:
lib/vienna.rb

Overview

Vienna::Static is just a wrapper for Rack::Static with sane and opinionated options.

It serves all files under the given root and doesn’t passes on requests for files that don’t exist.

Examples

use Vienna::Static, 'public'

Instance Method Summary collapse

Constructor Details

#initialize(app, root) ⇒ Static

Returns a new instance of Static.



35
36
37
38
# File 'lib/vienna.rb', line 35

def initialize(app, root)
  @app = app
  @root = root
end

Instance Method Details

#call(env) ⇒ Object



60
61
62
# File 'lib/vienna.rb', line 60

def call(env)
  Rack::Static.new(@app, options).call(env)
end

#header_rulesObject



52
53
54
# File 'lib/vienna.rb', line 52

def header_rules
  [[:all, {'Cache-Control' => 'public, max-age=3600'}]]
end

#indexObject



48
49
50
# File 'lib/vienna.rb', line 48

def index
  'index.html'
end

#optionsObject



56
57
58
# File 'lib/vienna.rb', line 56

def options
  {urls: urls, root: root, index: index, header_rules: header_rules}
end

#rootObject



44
45
46
# File 'lib/vienna.rb', line 44

def root
  @root
end

#urlsObject



40
41
42
# File 'lib/vienna.rb', line 40

def urls
  Dir.glob("#{root}/*").map { |f| f.sub(root, '') }
end