bust_rails_etags 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bust_rails_etags.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 nate
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,70 @@
1
+ # BustRailsEtags
2
+
3
+ Helps bust http caching on new deploys of a Rails app using the environment variable:
4
+
5
+ ENV["ETAG_VERSION_ID"]
6
+
7
+ Rails has awesome http caching abilities. However, when you deploy a new version of your Rails app, there isn't a good way to have that http cache get busted. And so browsers end up carrying around an old version.
8
+
9
+ One way of busting the cache is using:
10
+
11
+ ENV["RAILS_CACHE_ID"] = release_version["name"]
12
+
13
+ But changing that environment variable on deploys also busts things like your action and fragment caches. That's a bit too destructive.
14
+
15
+ So this gem creates a new environment variable you can use to bust only your http caches.
16
+
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ gem 'bust_rails_etags'
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install bust_rails_etags
31
+
32
+ ## Usage
33
+
34
+ The goal of this gem is to provide an environment variable you can change that will bust all of your http caches for you app on deployments.
35
+
36
+ The recommended way of doing that is to create an initializer file in your Rails app's config/initializers folder. You can call it bust_http_cache.rb
37
+
38
+ Your goal in that file is to set ENV["ETAG_VERSION_ID"] to something that will change on each Rails deployment.
39
+
40
+ On Heroku I can use the release numbers. So in my bust_http_cache.rb I can do:
41
+
42
+ ```
43
+ require 'heroku-api'
44
+
45
+ heroku = Heroku::API.new(:api_key => "2304u34oisefiou34342k3mdsd")
46
+ release_version = heroku.get_releases('myappname').body.last
47
+
48
+ ENV["ETAG_VERSION_ID"] = release_version["name"]
49
+ ```
50
+
51
+ Your process can be different depending on your deployment environment. What's important is that the deploy changes the value of ENV["ETAG_VERSION_ID"] across all nodes of your application, and that every node also has the same value of ENV["ETAG_VERSION_ID"]. So you probably wouldn't want to do something like this:
52
+
53
+ ```
54
+ ENV["ETAG_VERSION_ID"] = Time.now
55
+ ```
56
+
57
+ Because that will cause different servers to have different values of ENV["ETAG_VERSION_ID"] if they were initialized at even slightly different times.
58
+
59
+
60
+
61
+
62
+
63
+
64
+ ## Contributing
65
+
66
+ 1. Fork it
67
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
68
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
69
+ 4. Push to the branch (`git push origin my-new-feature`)
70
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/bust_rails_etags/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["nate"]
6
+ gem.email = ["nate@cityposh.com"]
7
+ gem.description = %q{Helps you bust your rails etags on new deploys.}
8
+ gem.summary = %q{Allows you to set ENV["ETAG_VERSION_ID"] in an initializer to that deploys will create new versions of your etags.}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "bust_rails_etags"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = BustRailsEtags::VERSION
17
+ end
@@ -0,0 +1,32 @@
1
+ require "bust_rails_etags/version"
2
+
3
+ module BustRailsEtags
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ alias_method_chain :etag=, :version_id
8
+ end
9
+
10
+ private
11
+ def etag_with_version_id=(etag)
12
+
13
+ etag_elements = []
14
+
15
+ if etag.is_a?(Array)
16
+ etag_elements = ENV['ETAG_VERSION_ID'] + etag
17
+ else
18
+ etag_elements << ENV['ETAG_VERSION_ID']
19
+ etag_elements << etag
20
+ end
21
+
22
+ self.etag_without_version_id = etag_elements
23
+ end
24
+
25
+ class Railtie < Rails::Railtie
26
+ initializer "etag_version_ids.initialize" do |app|
27
+ ActionDispatch::Response.class_eval do
28
+ include BustRailsEtags
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module BustRailsEtags
2
+ VERSION = "0.0.3"
3
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bust_rails_etags
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - nate
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-18 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Helps you bust your rails etags on new deploys.
15
+ email:
16
+ - nate@cityposh.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - bust_rails_etags.gemspec
27
+ - lib/bust_rails_etags.rb
28
+ - lib/bust_rails_etags/version.rb
29
+ homepage: ''
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.24
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: Allows you to set ENV["ETAG_VERSION_ID"] in an initializer to that deploys
53
+ will create new versions of your etags.
54
+ test_files: []