class Sgfa::Demo::WebCss

Simple Rack app which serves a static CSS file and passes all other requests along to another app.

Public Class Methods

new(css, path, app) click to toggle source

Initial setup

@param css [String] The CSS to serve @param path [String] Where to serve it @param app [#call] The app which gets everything else

# File lib/sgfa/demo/web_css.rb, line 30
def initialize(css, path, app)
  @app = app
  @css = css
  @path = path
  @header = {
    'Content-Type' => 'text/css; charset=utf-8',
    'Content-Length' => @css.bytesize.to_s,
  }
end

Public Instance Methods

call(env) click to toggle source

The Rack app

@param env [Hash] The Rack environment @return [Array] Rack return of status, headers, and body

# File lib/sgfa/demo/web_css.rb, line 47
def call(env)
  if env['PATH_INFO'] == @path && env['REQUEST_METHOD'] == 'GET'
    exp = (Time.now + 60*60).rfc2822
    @header['Expires'] = exp
    [200, @header, [@css]]
  else
    @app.call(env)
  end
end