caching_mailer 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in crm_repo.gemspec
4
+ gemspec
@@ -0,0 +1,102 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ caching_mailer (1.0)
5
+ rails (~> 3.2.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ actionmailer (3.2.13)
11
+ actionpack (= 3.2.13)
12
+ mail (~> 2.5.3)
13
+ actionpack (3.2.13)
14
+ activemodel (= 3.2.13)
15
+ activesupport (= 3.2.13)
16
+ builder (~> 3.0.0)
17
+ erubis (~> 2.7.0)
18
+ journey (~> 1.0.4)
19
+ rack (~> 1.4.5)
20
+ rack-cache (~> 1.2)
21
+ rack-test (~> 0.6.1)
22
+ sprockets (~> 2.2.1)
23
+ activemodel (3.2.13)
24
+ activesupport (= 3.2.13)
25
+ builder (~> 3.0.0)
26
+ activerecord (3.2.13)
27
+ activemodel (= 3.2.13)
28
+ activesupport (= 3.2.13)
29
+ arel (~> 3.0.2)
30
+ tzinfo (~> 0.3.29)
31
+ activeresource (3.2.13)
32
+ activemodel (= 3.2.13)
33
+ activesupport (= 3.2.13)
34
+ activesupport (3.2.13)
35
+ i18n (= 0.6.1)
36
+ multi_json (~> 1.0)
37
+ arel (3.0.2)
38
+ builder (3.0.4)
39
+ diff-lcs (1.2.1)
40
+ erubis (2.7.0)
41
+ hike (1.2.1)
42
+ i18n (0.6.1)
43
+ journey (1.0.4)
44
+ json (1.7.7)
45
+ mail (2.5.3)
46
+ i18n (>= 0.4.0)
47
+ mime-types (~> 1.16)
48
+ treetop (~> 1.4.8)
49
+ mime-types (1.21)
50
+ multi_json (1.7.1)
51
+ polyglot (0.3.3)
52
+ rack (1.4.5)
53
+ rack-cache (1.2)
54
+ rack (>= 0.4)
55
+ rack-ssl (1.3.3)
56
+ rack
57
+ rack-test (0.6.2)
58
+ rack (>= 1.0)
59
+ rails (3.2.13)
60
+ actionmailer (= 3.2.13)
61
+ actionpack (= 3.2.13)
62
+ activerecord (= 3.2.13)
63
+ activeresource (= 3.2.13)
64
+ activesupport (= 3.2.13)
65
+ bundler (~> 1.0)
66
+ railties (= 3.2.13)
67
+ railties (3.2.13)
68
+ actionpack (= 3.2.13)
69
+ activesupport (= 3.2.13)
70
+ rack-ssl (~> 1.3.2)
71
+ rake (>= 0.8.7)
72
+ rdoc (~> 3.4)
73
+ thor (>= 0.14.6, < 2.0)
74
+ rake (10.0.3)
75
+ rdoc (3.12.2)
76
+ json (~> 1.4)
77
+ rspec (2.13.0)
78
+ rspec-core (~> 2.13.0)
79
+ rspec-expectations (~> 2.13.0)
80
+ rspec-mocks (~> 2.13.0)
81
+ rspec-core (2.13.1)
82
+ rspec-expectations (2.13.0)
83
+ diff-lcs (>= 1.1.3, < 2.0)
84
+ rspec-mocks (2.13.0)
85
+ sprockets (2.2.2)
86
+ hike (~> 1.2)
87
+ multi_json (~> 1.0)
88
+ rack (~> 1.0)
89
+ tilt (~> 1.1, != 1.3.0)
90
+ thor (0.17.0)
91
+ tilt (1.3.6)
92
+ treetop (1.4.12)
93
+ polyglot
94
+ polyglot (>= 0.3.1)
95
+ tzinfo (0.3.37)
96
+
97
+ PLATFORMS
98
+ ruby
99
+
100
+ DEPENDENCIES
101
+ caching_mailer!
102
+ rspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Mike Demers <mike_(at)_9astronauts.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ = CachingMailer
2
+
3
+ Enables the use of fragment caching in ActionMailer views.
4
+
5
+ Shares the cache configuration of ActionController::Base.
6
+
7
+ == Usage
8
+
9
+ Configure fragment caching in "config/environment.rb" (or in the
10
+ configuration file for a specific environment such as
11
+ "config/environments/production.rb"):
12
+
13
+ config.action_controller.perform_caching = true
14
+ config.cache_store = :file_store, File.join(Rails.root, 'tmp', 'cache')
15
+
16
+
17
+ For the mailer "app/models/hello_mailer.rb":
18
+
19
+ class HelloMailer < ActionMailer::Base
20
+ def hello
21
+ subject "Hello, World"
22
+ recipients "you@foo.com"
23
+ from "me@bar.com"
24
+ sent_on Time.now
25
+ end
26
+ end
27
+
28
+ And the template "app/views/hello_mailer/hello.text.plain.erb":
29
+
30
+ Hello, World!
31
+
32
+ This is an computationally expensive list:
33
+
34
+ <% cache("mail/expensive-list") do %>
35
+ <% ExpensiveOperation.results.each do |result| %>
36
+ * Item #<%= result.id %>: "<%= result.title %>"
37
+ <% end %>
38
+ <% end %>
39
+
40
+ The computationally expensive method `ExpensiveOperation.results` will only
41
+ be invoked once. Subsequent emails will use the cached result.
42
+
43
+ For automatic expiration, try including a time value in the cache key. This
44
+ example will generate a new cache entry every 2 hours (removal of stale
45
+ entries is left as an exercise to the reader):
46
+
47
+ <% cache("mail/expensive-list-#{Time.now.to_i / 2.hours.to_i}") do %>
48
+ <% ExpensiveOperation.results.each do |result| %>
49
+ * Item #<%= result.id %>: "<%= result.title %>"
50
+ <% end %>
51
+ <% end %>
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rspec/core/rake_task"
4
+ RSpec::Core::RakeTask.new('spec')
5
+ task :default => :spec
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "caching_mailer"
6
+ s.version = "1.0"
7
+ s.authors = ["Mike Demers", "Tim Dorr"]
8
+ s.email = ["timdorr@timdorr.com"]
9
+ s.homepage = "https://github.com/timdorr/caching_mailer"
10
+ s.summary = %q{Adds fragment caching to ActionMailer}
11
+ s.description = %q{Uses ActionController to provide fragment caching to ActionMailer}
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ["lib"]
17
+
18
+ # specify any dependencies here; for example:
19
+ s.add_development_dependency("rspec")
20
+ s.add_runtime_dependency("rails", ["~> 3.2.0"])
21
+ end
@@ -0,0 +1,28 @@
1
+ module CachingMailer
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ delegate :cache, :cache_store, :perform_caching, :cache_configured?, :benchmark, :silence, :to => ActionController::Base
6
+ include ActionController::Caching::Fragments
7
+ end
8
+
9
+ class Railtie < Rails::Railtie
10
+ ActiveSupport.on_load(:action_mailer) do
11
+ include CachingMailer
12
+ end
13
+ end
14
+
15
+ protected
16
+
17
+ def fragment_cache_key(key)
18
+ ActiveSupport::Cache.expand_cache_key(key.is_a?(Hash) ? url_for(key).split("://").last : key, 'views/mailers')
19
+ end
20
+
21
+ def cache(key, options = {}, &block)
22
+ if cache_configured?
23
+ cache_store.fetch(ActiveSupport::Cache.expand_cache_key(key, :mailer), options, &block)
24
+ else
25
+ yield
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class CachingMailerTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: caching_mailer
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mike Demers
9
+ - Tim Dorr
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-03-19 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rails
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: 3.2.0
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 3.2.0
47
+ description: Uses ActionController to provide fragment caching to ActionMailer
48
+ email:
49
+ - timdorr@timdorr.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - Gemfile.lock
57
+ - LICENSE
58
+ - README.rdoc
59
+ - Rakefile
60
+ - caching_mailer.gemspec
61
+ - lib/caching_mailer.rb
62
+ - test/caching_mailer_test.rb
63
+ - test/test_helper.rb
64
+ homepage: https://github.com/timdorr/caching_mailer
65
+ licenses: []
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ segments:
77
+ - 0
78
+ hash: -673683854124937832
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ segments:
86
+ - 0
87
+ hash: -673683854124937832
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 1.8.25
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: Adds fragment caching to ActionMailer
94
+ test_files:
95
+ - test/caching_mailer_test.rb
96
+ - test/test_helper.rb