rack-sprockets 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,17 +38,16 @@ module Rack::Sprockets
38
38
  File.extname(path_info)
39
39
  end
40
40
 
41
+ def cache
42
+ File.join(options(:root), options(:public), options(:hosted_at))
43
+ end
44
+
41
45
  # The Rack::Sprockets::Source that the request is for
42
46
  def source
43
47
  @source ||= begin
44
- cache = if Rack::Sprockets.config.cache?
45
- File.join(options(:root), options(:public), options(:hosted_at))
46
- else
47
- nil
48
- end
49
48
  source_opts = {
50
49
  :folder => File.join(options(:root), options(:source)),
51
- :cache => cache,
50
+ :cache => Rack::Sprockets.config.cache? ? cache : nil,
52
51
  :compress => Rack::Sprockets.config.compress,
53
52
  :secretary => {
54
53
  :root => options(:root),
@@ -66,12 +65,25 @@ module Rack::Sprockets
66
65
  JS_PATH_FORMATS.include?(path_resource_format)
67
66
  end
68
67
 
68
+ def hosted_at?
69
+ File.basename(File.dirname(path_info)) == File.basename(options(:hosted_at))
70
+ end
71
+
72
+ def exists?
73
+ File.exists?(File.join(cache, "#{path_resource_name}#{path_resource_format}"))
74
+ end
75
+
69
76
  # Determine if the request is for an existing Sprockets source file
70
77
  # This will be called on every request so speed is an issue
71
- # => first check if the request is a GET on a js resource (fast)
72
- # => then check for sprockets source files that match the request (slow)
78
+ # => first check if the request is a GET on a js resource in :hosted_at (fast)
79
+ # => don't process if a file already exists in :hosted_at
80
+ # => otherwise, check for sprockets source files that match the request (slow)
73
81
  def for_sprockets?
74
- get? && for_js? && !source.files.empty?
82
+ get? &&
83
+ for_js? &&
84
+ hosted_at? &&
85
+ !exists? &&
86
+ !source.files.empty?
75
87
  end
76
88
 
77
89
  end
@@ -3,7 +3,7 @@ module RackSprockets
3
3
 
4
4
  MAJOR = 1
5
5
  MINOR = 0
6
- TINY = 1
6
+ TINY = 2
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-sprockets
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding