turbo-sprockets-rails3 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,7 +8,8 @@
8
8
 
9
9
  ### Disclaimer
10
10
 
11
- Please test this out thoroughly on your local machine before deploying to a production site, and open an issue on GitHub if you have any problems. By using this software you agree to the terms and conditions in the [MIT license](https://github.com/ndbroadbent/turbo-sprockets-rails3/blob/master/MIT-LICENSE).
11
+ `turbo-sprockets-rails3` can now be considered relatively stable. A lot of compatibility issues and bugs have been solved, so you shouldn't run into any problems.
12
+ However, please do test it out on your local machine before deploying to a production site, and open an issue on GitHub if you have any problems. By using this software you agree to the terms and conditions in the [MIT license](https://github.com/ndbroadbent/turbo-sprockets-rails3/blob/master/MIT-LICENSE).
12
13
 
13
14
  ## Supported Versions
14
15
 
@@ -39,6 +40,20 @@ Go on, run `rake assets:precompile` again, and it should be a whole lot faster t
39
40
 
40
41
  Enjoy your lightning fast deploys!
41
42
 
43
+ ## Removing Expired Assets
44
+
45
+ `turbo-sprockets-rails3` can now remove expired assets after each compile. It will run the `assets:clean_expired` task after `assets:precompile`, if the environment variable `CLEAN_EXPIRED_ASSETS` is set to `true`.
46
+ Any assets that are no longer referenced by `manifest.yml`, and are older than 7 days (by default) will be deleted.
47
+
48
+ You can expire old assets after precompile by running `CLEAN_EXPIRED_ASSETS=true rake assets:precompile`.
49
+
50
+ You can configure the expiry time by setting `config.assets.expire_after` in `config/environments/production.rb`.
51
+ An expiry time of 2 weeks could be configured with the following code:
52
+
53
+ ```ruby
54
+ config.assets.expire_after 2.weeks
55
+ ```
56
+
42
57
  ## Compatibility
43
58
 
44
59
  ### [asset_sync](https://github.com/rumblelabs/asset_sync)
@@ -102,6 +102,40 @@ namespace :assets do
102
102
  end
103
103
  end
104
104
 
105
+ desc "Remove old assets that aren't referenced by manifest.yml"
106
+ task :clean_expired do
107
+ invoke_or_reboot_rake_task "assets:clean_expired:all"
108
+ end
109
+
110
+ namespace :clean_expired do
111
+ task :all do
112
+ # Remove assets that aren't referenced by manifest.yml,
113
+ # and are older than `config.assets.expire_after` (default 7 days).
114
+ config = ::Rails.application.config
115
+ expire_after = config.assets.expire_after || 7.days
116
+ public_asset_path = File.join(::Rails.public_path, config.assets.prefix)
117
+
118
+ # Also handle gzipped assets
119
+ known_assets = config.assets.digests.to_a.flatten.map do |asset|
120
+ [asset, "#{asset}.gz"]
121
+ end.flatten
122
+ known_assets += %w(manifest.yml sources_manifest.yml)
123
+
124
+ Dir.glob(File.join(public_asset_path, '**/*')).each do |asset|
125
+ next if File.directory?(asset)
126
+ logical_path = asset.sub("#{public_asset_path}/", '')
127
+
128
+ unless logical_path.in?(known_assets)
129
+ # Delete asset if older than expire_after seconds
130
+ if File.mtime(asset) < (Time.now - expire_after)
131
+ ::Rails.logger.debug "Removing expired asset: #{logical_path}"
132
+ FileUtils.rm_f asset
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
138
+
105
139
  desc "Remove compiled assets"
106
140
  task :clean do
107
141
  invoke_or_reboot_rake_task "assets:clean:all"
@@ -138,4 +172,9 @@ task_enhancements.each do |task_name, actions|
138
172
  actions.each do |proc|
139
173
  Rake::Task[task_name].enhance &proc
140
174
  end
175
+ end
176
+
177
+ # Clean expired assets after asset precompile, if CLEAN_EXPIRED_ASSETS is set
178
+ Rake::Task["assets:precompile:all"].enhance do
179
+ Rake::Task["assets:clean_expired:all"].invoke if ENV['CLEAN_EXPIRED_ASSETS'].in? %w(true yes 1)
141
180
  end
@@ -1,3 +1,3 @@
1
1
  module TurboSprockets
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  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.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: