Class: Rack::Sprockets::Request
- Inherits:
-
Request
- Object
- Request
- Rack::Sprockets::Request
show all
- 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']
Constants included
from Options
Options::COLLECTION_OPTS, Options::RACK_ENV_NS
Instance Method Summary
collapse
Methods included from Options
included
Instance Method Details
#cache ⇒ Object
59
60
61
|
# File 'lib/rack/sprockets/request.rb', line 59
def cache
File.join(options(:root), options(:public), hosted_at_option)
end
|
#cached? ⇒ Boolean
90
91
92
|
# File 'lib/rack/sprockets/request.rb', line 90
def cached?
File.exists?(File.join(cache, "#{path_info_resource}#{path_info_format}"))
end
|
#for_sprockets? ⇒ Boolean
Determine if the request is for a non-cached 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 has already been cached
> otherwise, check for sprockets source files that match the request (slow)
99
100
101
102
103
104
105
|
# File 'lib/rack/sprockets/request.rb', line 99
def for_sprockets?
get? && for_js? &&
hosted_at? &&
!cached? && !source.files.empty? end
|
#hosted_at? ⇒ Boolean
86
87
88
|
# File 'lib/rack/sprockets/request.rb', line 86
def hosted_at?
path_info =~ /^#{hosted_at_option}/
end
|
#hosted_at_option ⇒ Object
33
34
35
36
37
38
|
# File 'lib/rack/sprockets/request.rb', line 33
def hosted_at_option
@hosted_at_option ||= options(:hosted_at).sub(/\/+$/, '').sub(/^\/*/, '/')
end
|
#http_accept ⇒ Object
25
26
27
|
# File 'lib/rack/sprockets/request.rb', line 25
def http_accept
@env['HTTP_ACCEPT']
end
|
#path_info ⇒ Object
29
30
31
|
# File 'lib/rack/sprockets/request.rb', line 29
def path_info
@env['PATH_INFO']
end
|
55
56
57
|
# File 'lib/rack/sprockets/request.rb', line 55
def path_info_format
@path_info_format ||= File.extname(path_info.gsub(/\/+/, '/'))
end
|
#path_info_resource ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/rack/sprockets/request.rb', line 40
def path_info_resource
@path_info_resource ||= File.join(
File.dirname(path_info.gsub(/\/+/, '/')).sub(/^#{hosted_at_option}/, ''),
File.basename(path_info.gsub(/\/+/, '/'), path_info_format)
).sub(/^\/*/, '/')
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/rack/sprockets/request.rb', line 64
def source
@source ||= begin
source_opts = {
:folder => File.join(options(:root), options(:source)),
:cache => Rack::Sprockets.config.cache? ? cache : nil,
:compress => Rack::Sprockets.config.compress,
:secretary => {
:root => options(:root),
:load_path => options(:load_path),
:expand_paths => options(:expand_paths)
}
}
Source.new(path_info_resource, source_opts)
end
end
|