Sha256: 404177ed5b437163ebbeba653df2849750cb41cc55a3bfcbf736fcdb1b44a9fa

Contents?: true

Size: 934 Bytes

Versions: 25

Compression:

Stored size: 934 Bytes

Contents

require 'dassets/server/request'
require 'dassets/server/response'

# Rack middleware for serving Dassets asset files

module Dassets
  class Server

    def initialize(app)
      @app = app
    end

    # The Rack call interface. The receiver acts as a prototype and runs
    # each request in a clone object unless the +rack.run_once+ variable is
    # set in the environment. Ripped from:
    # http://github.com/rtomayko/rack-cache/blob/master/lib/rack/cache/context.rb
    def call(env)
      if env['rack.run_once']
        call! env
      else
        clone.call! env
      end
    end

    # The real Rack call interface.
    # if an asset file is being requested, this is an endpoint - otherwise, call
    # on up to the app as normal
    def call!(env)
      if (request = Request.new(env)).for_asset_file?
        Response.new(env, request.asset_file).to_rack
      else
        @app.call(env)
      end
    end

  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
dassets-0.14.5 lib/dassets/server.rb
dassets-0.14.4 lib/dassets/server.rb
dassets-0.14.3 lib/dassets/server.rb
dassets-0.14.2 lib/dassets/server.rb
dassets-0.14.1 lib/dassets/server.rb
dassets-0.14.0 lib/dassets/server.rb
dassets-0.13.2 lib/dassets/server.rb
dassets-0.13.1 lib/dassets/server.rb
dassets-0.13.0 lib/dassets/server.rb
dassets-0.12.0 lib/dassets/server.rb
dassets-0.11.0 lib/dassets/server.rb
dassets-0.10.1 lib/dassets/server.rb
dassets-0.10.0 lib/dassets/server.rb
dassets-0.9.0 lib/dassets/server.rb
dassets-0.8.0 lib/dassets/server.rb
dassets-0.7.0 lib/dassets/server.rb
dassets-0.6.2 lib/dassets/server.rb
dassets-0.6.1 lib/dassets/server.rb
dassets-0.6.0 lib/dassets/server.rb
dassets-0.5.0 lib/dassets/server.rb