Sha256: ddf2c7796edc67aa7465db5716607c76983a5bb7e2806bd84b56aa95e6345c65

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

require 'sprockets'
require 'sprockets/rails/helper'

module Sprockets
  module Rails
    class Environment < Sprockets::Environment
      class NoDigestError < StandardError
        def initialize(asset)
          msg = "Assets should not be requested directly without their digests: " <<
                "Use the helpers in ActionView::Helpers to request #{asset}"
          super(msg)
        end
      end

      def call(env)
        if Sprockets::Rails::Helper.raise_runtime_errors && context_class.digest_assets
          path = unescape(env['PATH_INFO'].to_s.sub(/^\//, ''))

          if fingerprint = path_fingerprint(path)
            path = path.sub("-#{fingerprint}", '')
          else
            raise NoDigestError.new(path)
          end

          asset = find_asset(path)
          if asset && asset.digest != fingerprint
            asset_path = File.join(context_class.assets_prefix || "/", asset.digest_path)
            asset_path += '?' + env['QUERY_STRING'] if env['QUERY_STRING']
            [302, {"Location" => asset_path}, []]
          else
            super(env)
          end
        else
          super(env)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sprockets-rails-3.0.0.beta1 lib/sprockets/rails/environment.rb