Class: Steam::Connection::Static

Inherits:
Rack::Static
  • Object
show all
Defined in:
lib/steam/connection/static.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Static

Returns a new instance of Static.



6
7
8
9
10
11
# File 'lib/steam/connection/static.rb', line 6

def initialize(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  options[:urls] ||= %w(/images /javascripts /stylesheets)
  app = args.pop
  super(app || lambda { response_404 }, options)
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/steam/connection/static.rb', line 13

def call(env)
  status, headers, response = super

  response = case response
  when Rack::File
    Rack::Response.new(::File.read(response.path), status, headers).to_a
  when Array
    Rack::Response.new(response.first, status, headers).to_a
  else
    [status, headers, response]
  end

  response
end

#response_404Object



28
29
30
# File 'lib/steam/connection/static.rb', line 28

def response_404
  Rack::Response.new('', 404).to_a
end