Class: Rack::Sprockets::Request
- Inherits:
-
Request
- Object
- Request
- Rack::Sprockets::Request
- Includes:
- Options
- Defined in:
- lib/rack/sprockets/request.rb
Overview
Provides access to the HTTP request. Request objects respond to everything defined by Rack::Request as well as some additional convenience methods defined here
Constant Summary collapse
- JS_PATH_FORMATS =
['.js']
Instance Method Summary collapse
- #for_js? ⇒ Boolean
-
#for_sprockets? ⇒ Boolean
Determine if the request is for an existing Sprockets source file This will be called on every request so speed is an issue => first check if the request is a GET on a js resource (fast) => then check for sprockets source files that match the request (slow).
- #http_accept ⇒ Object
- #path_info ⇒ Object
- #path_resource_format ⇒ Object
- #path_resource_name ⇒ Object
-
#request_method ⇒ Object
The HTTP request method.
-
#source ⇒ Object
The Rack::Sprockets::Source that the request is for.
Instance Method Details
#for_js? ⇒ Boolean
63 64 65 66 67 |
# File 'lib/rack/sprockets/request.rb', line 63 def for_js? (http_accept && http_accept.include?(Rack::Sprockets::MIME_TYPE)) || (media_type && media_type.include?(Rack::Sprockets::MIME_TYPE )) || JS_PATH_FORMATS.include?(path_resource_format) end |
#for_sprockets? ⇒ Boolean
Determine if the request is for an existing Sprockets source file This will be called on every request so speed is an issue
> first check if the request is a GET on a js resource (fast)
> then check for sprockets source files that match the request (slow)
73 74 75 |
# File 'lib/rack/sprockets/request.rb', line 73 def for_sprockets? get? && for_js? && !source.files.empty? end |
#http_accept ⇒ Object
29 30 31 |
# File 'lib/rack/sprockets/request.rb', line 29 def http_accept @env['HTTP_ACCEPT'] end |
#path_info ⇒ Object
25 26 27 |
# File 'lib/rack/sprockets/request.rb', line 25 def path_info @env['PATH_INFO'] end |
#path_resource_format ⇒ Object
37 38 39 |
# File 'lib/rack/sprockets/request.rb', line 37 def path_resource_format File.extname(path_info) end |
#path_resource_name ⇒ Object
33 34 35 |
# File 'lib/rack/sprockets/request.rb', line 33 def path_resource_name File.basename(path_info, path_resource_format) end |
#request_method ⇒ Object
The HTTP request method. This is the standard implementation of this method but is respecified here due to libraries that attempt to modify the behavior to respect POST tunnel method specifiers. We always want the real request method.
21 22 23 |
# File 'lib/rack/sprockets/request.rb', line 21 def request_method @env['REQUEST_METHOD'] end |
#source ⇒ Object
The Rack::Sprockets::Source that the request is for
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rack/sprockets/request.rb', line 42 def source @source ||= begin cache = if Rack::Sprockets.config.cache? File.join((:root), (:public), (:hosted_at)) else nil end source_opts = { :folder => File.join((:root), (:source)), :cache => cache, :compress => Rack::Sprockets.config.compress, :secretary => { :root => (:root), :load_path => (:load_path), :expand_paths => (:expand_paths) } } Source.new(path_resource_name, source_opts) end end |