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
- #cache ⇒ Object
- #exists? ⇒ Boolean
- #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 in :hosted_at (fast) => don’t process if a file already exists in :hosted_at => otherwise, check for sprockets source files that match the request (slow).
- #hosted_at? ⇒ Boolean
- #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
#cache ⇒ Object
41 42 43 |
# File 'lib/rack/sprockets/request.rb', line 41 def cache File.join((:root), (:public), (:hosted_at)) end |
#exists? ⇒ Boolean
72 73 74 |
# File 'lib/rack/sprockets/request.rb', line 72 def exists? File.exists?(File.join(cache, "#{path_resource_name}#{path_resource_format}")) end |
#for_js? ⇒ Boolean
62 63 64 65 66 |
# File 'lib/rack/sprockets/request.rb', line 62 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 in :hosted_at (fast)
> don’t process if a file already exists in :hosted_at
> otherwise, check for sprockets source files that match the request (slow)
81 82 83 84 85 86 87 |
# File 'lib/rack/sprockets/request.rb', line 81 def for_sprockets? get? && for_js? && hosted_at? && !exists? && !source.files.empty? end |
#hosted_at? ⇒ Boolean
68 69 70 |
# File 'lib/rack/sprockets/request.rb', line 68 def hosted_at? File.basename(File.dirname(path_info)) == File.basename((:hosted_at)) 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
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rack/sprockets/request.rb', line 46 def source @source ||= begin source_opts = { :folder => File.join((:root), (:source)), :cache => Rack::Sprockets.config.cache? ? cache : nil, :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 |