turbo-sprockets-rails3 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/Rakefile +3 -0
- data/lib/turbo-sprockets/tasks/assets.rake +26 -30
- data/lib/turbo-sprockets/version.rb +1 -1
- metadata +7 -2
data/README.md
CHANGED
@@ -45,7 +45,7 @@ Enjoy your lightning fast deploys!
|
|
45
45
|
`turbo-sprockets-rails3` can now remove expired assets after each compile. If the environment variable `CLEAN_EXPIRED_ASSETS` is set to `true`, the `assets:clean_expired` task will be run after `assets:precompile`.
|
46
46
|
An asset will be deleted if it is no longer referenced by `manifest.yml`, and is more than 7 days (default) older than the **previous** compiled assets.
|
47
47
|
|
48
|
-
Before the `assets:precompile` task runs, it stores the modification time of the current `manifest.yml` in a file called `expire_assets_after.yml`. When the `assets:clean_expired` task runs, it looks up the time in `expire_assets_after.yml`, and won't expire any assets that were created
|
48
|
+
Before the `assets:precompile` task runs, it stores the modification time of the current `manifest.yml` in a file called `expire_assets_after.yml`. When the `assets:clean_expired` task runs, it looks up the time in `expire_assets_after.yml`, and won't expire any assets that were created on or after than that time.
|
49
49
|
|
50
50
|
To expire old assets after precompile, you should compile assets by running `CLEAN_EXPIRED_ASSETS=true rake assets:precompile`. Alternatively, you can run `rake assets:precompile assets:clean_expired`.
|
51
51
|
|
data/Rakefile
CHANGED
@@ -35,6 +35,15 @@ namespace :assets do
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
# Returns an array of assets recognized by config.assets.digests,
|
39
|
+
# including gzipped assets and manifests
|
40
|
+
def known_assets
|
41
|
+
assets = Rails.application.config.assets.digests.to_a.flatten.map do |asset|
|
42
|
+
[asset, "#{asset}.gz"]
|
43
|
+
end.flatten
|
44
|
+
assets + %w(manifest.yml sources_manifest.yml)
|
45
|
+
end
|
46
|
+
|
38
47
|
desc "Compile all the assets named in config.assets.precompile"
|
39
48
|
task :precompile do
|
40
49
|
invoke_or_reboot_rake_task "assets:precompile:all"
|
@@ -61,14 +70,14 @@ namespace :assets do
|
|
61
70
|
env = Rails.application.assets
|
62
71
|
target = File.join(::Rails.public_path, config.assets.prefix)
|
63
72
|
|
64
|
-
#
|
65
|
-
#
|
73
|
+
# Before first compile, set the mtime of all current assets to current time.
|
74
|
+
# This time reflects the last time the assets were being used.
|
66
75
|
if digest.nil?
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
File.
|
71
|
-
|
76
|
+
::Rails.logger.debug "Updating mtimes for current assets..."
|
77
|
+
known_assets.each do |asset|
|
78
|
+
full_path = File.join(target, asset)
|
79
|
+
if File.exist?(full_path)
|
80
|
+
File.utime(Time.now, Time.now, full_path)
|
72
81
|
end
|
73
82
|
end
|
74
83
|
end
|
@@ -119,39 +128,26 @@ namespace :assets do
|
|
119
128
|
invoke_or_reboot_rake_task "assets:clean_expired:all"
|
120
129
|
end
|
121
130
|
|
131
|
+
# Remove assets that haven't been deployed since `config.assets.expire_after` (default 7 days).
|
132
|
+
# The precompile task updates the mtime of the current assets before compiling,
|
133
|
+
# which indicates when they were last in use.
|
134
|
+
#
|
135
|
+
# The current assets are ignored, which is faster than the alternative of
|
136
|
+
# setting their mtimes only to check them again.
|
122
137
|
namespace :clean_expired do
|
123
138
|
task :all => ["assets:environment"] do
|
124
|
-
# Remove assets that aren't referenced by manifest.yml,
|
125
|
-
# and are older than `config.assets.expire_after` (default 7 days),
|
126
|
-
# counting from the **previous** compile.
|
127
139
|
config = ::Rails.application.config
|
128
140
|
expire_after = config.assets.expire_after || 7.days
|
129
141
|
public_asset_path = File.join(::Rails.public_path, config.assets.prefix)
|
130
|
-
|
131
|
-
# Also handle gzipped assets
|
132
|
-
known_assets = config.assets.digests.to_a.flatten.map do |asset|
|
133
|
-
[asset, "#{asset}.gz"]
|
134
|
-
end.flatten
|
135
|
-
known_assets += %w(manifest.yml sources_manifest.yml)
|
142
|
+
@known_assets = known_assets
|
136
143
|
|
137
144
|
Dir.glob(File.join(public_asset_path, '**/*')).each do |asset|
|
138
145
|
next if File.directory?(asset)
|
139
146
|
logical_path = asset.sub("#{public_asset_path}/", '')
|
140
147
|
|
141
|
-
unless logical_path.in?(known_assets)
|
142
|
-
#
|
143
|
-
|
144
|
-
expire_after_base_time = Time.now
|
145
|
-
|
146
|
-
expire_after_file = File.join(::Rails.public_path, config.assets.prefix, 'expire_assets_after.yml')
|
147
|
-
if File.exist?(expire_after_file)
|
148
|
-
if time = YAML.load_file(expire_after_file)[:expire_assets_after]
|
149
|
-
expire_after_base_time = time
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
# Delete asset if older than expire_after seconds
|
154
|
-
if File.mtime(asset) < (expire_after_base_time - expire_after)
|
148
|
+
unless logical_path.in?(@known_assets)
|
149
|
+
# Delete asset if not used for more than expire_after seconds
|
150
|
+
if File.mtime(asset) < (Time.now - expire_after)
|
155
151
|
::Rails.logger.debug "Removing expired asset: #{logical_path}"
|
156
152
|
FileUtils.rm_f asset
|
157
153
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turbo-sprockets-rails3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -100,12 +100,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
100
|
- - ! '>='
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
hash: 4460991150311061382
|
103
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
107
|
none: false
|
105
108
|
requirements:
|
106
109
|
- - ! '>='
|
107
110
|
- !ruby/object:Gem::Version
|
108
111
|
version: '0'
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
hash: 4460991150311061382
|
109
115
|
requirements: []
|
110
116
|
rubyforge_project:
|
111
117
|
rubygems_version: 1.8.24
|
@@ -134,4 +140,3 @@ test_files:
|
|
134
140
|
- test/assets_debugging_test.rb
|
135
141
|
- test/sprockets_helper_with_routes_test.rb
|
136
142
|
- test/abstract_unit.rb
|
137
|
-
has_rdoc:
|