Class: Triboelectric::Static

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

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Static



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

def initialize(app, options = {})
  Uploader.upload(options) if options.fetch(:upload, true)
  @app    = app
  @static = Rack::Static.new(@app, options)
  @bucket = options[:bucket]
  @root   = options[:root]
end

Instance Method Details

#call(env) ⇒ Object



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

def call(env)
  return @app.call(env) unless @static.can_serve(env[Rack::PATH_INFO])

  status, headers, body = @static.call(env)

  if (object = get_object(env, status))
    headers[Rack::CONTENT_TYPE]   = object.content_type
    headers[Rack::CONTENT_LENGTH] = object.content_length
    status = 200
    body   = object.body
  end

  [status, headers, body]
end