redis_cache_mailer_delivery 0.0.1
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.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/LICENSE +22 -0
- data/README.md +54 -0
- data/Rakefile +2 -0
- data/lib/redis_cache_mailer_delivery.rb +16 -0
- data/lib/redis_cache_mailer_delivery/action_mailer/base.rb +26 -0
- data/lib/redis_cache_mailer_delivery/mail/cache_delivery.rb +32 -0
- data/lib/redis_cache_mailer_delivery/railtie.rb +16 -0
- data/lib/redis_cache_mailer_delivery/version.rb +3 -0
- data/redis_cache_mailer_delivery.gemspec +24 -0
- data/spec/redis_cache_mailer_delivery_spec.rb +10 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/faked_rails.rb +14 -0
- metadata +142 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.3@redis_cache_mailer_delivery
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
# NOTE: When using watch with a block, you must return all files that should be reloaded.
|
5
|
+
guard :rspectacle, :cli => '--format documentation --backtrace' do
|
6
|
+
watch('spec/spec_helper.rb') { %w(spec/spec_helper spec) }
|
7
|
+
|
8
|
+
watch(%r{^spec/.+_spec\.rb$})
|
9
|
+
|
10
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| ["lib/#{m[1]}.rb", "spec/lib/#{m[1]}_spec.rb"] }
|
11
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Yi Wen
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# RedisCacheMailerDelivery
|
2
|
+
|
3
|
+
This gem is inspired by https://github.com/p0deje/action_mailer_cache_delivery.
|
4
|
+
|
5
|
+
If you are using Resque for sending mails asynchronously, and you want to test the mail sending asynchronously in your integration tests, then you can use this gem for just that.
|
6
|
+
|
7
|
+
The gem adds a new delivery method to the ActionMailer and it stores the marshaled Mail::Message being delivered into a redis list which can be fetched by any other processes.
|
8
|
+
|
9
|
+
A separate Resque worker process deliver emails, which being written into a redis storage. The test process (such as a cucumber step can then fetch the mail for examination).
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'redis_cache_mailer_delivery'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install redis_cache_mailer_delivery
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
In a Rails project, in your environment files such as config/environments/cucumber.rb
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
config.action_mailer.delivery_method = :redis_cache
|
31
|
+
config.action_mailer.redis_cache_settings = { :redis_key_name => "a_key_name_for_all_stored_emails" }
|
32
|
+
```
|
33
|
+
|
34
|
+
You don't have to define the redis_key_name, the default is
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
"redis_cache_mailer_delivery:mail_messages"
|
38
|
+
```
|
39
|
+
|
40
|
+
All the mails being delivered will be written into the redis storage. You can use
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
ActionMailer::Base.cached_deliveries
|
44
|
+
```
|
45
|
+
|
46
|
+
to access all the mails
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'action_mailer'
|
2
|
+
require 'redis_cache_mailer_delivery/version'
|
3
|
+
require 'redis_cache_mailer_delivery/mail/cache_delivery'
|
4
|
+
require 'redis_cache_mailer_delivery/action_mailer/base'
|
5
|
+
|
6
|
+
module RedisCacheMailerDelivery
|
7
|
+
class << self
|
8
|
+
def install
|
9
|
+
ActionMailer::Base.add_delivery_method :redis_cache, Mail::CacheDelivery,
|
10
|
+
:redis_key_name => "redis_cache_mailer_delivery:mail_messages"
|
11
|
+
end
|
12
|
+
|
13
|
+
end # << self
|
14
|
+
end # RedisCacheMailerDelivery
|
15
|
+
require 'redis_cache_mailer_delivery/railtie'
|
16
|
+
require "redis_cache_mailer_delivery/version"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ActionMailer
|
2
|
+
class Base
|
3
|
+
class << self
|
4
|
+
|
5
|
+
#
|
6
|
+
# Returns an array of delivered mails.
|
7
|
+
#
|
8
|
+
# @return [Array] array of mails (each mail is an instance of Mail.)
|
9
|
+
#
|
10
|
+
def cached_deliveries
|
11
|
+
list = Redis::List.new redis_cache_settings[:redis_key_name], :marshal => true
|
12
|
+
list.values.map{|m|Marshal.load(m)}
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# Clears delivered mails.
|
17
|
+
#
|
18
|
+
# It also cleans ActionMailer::Base.deliveries
|
19
|
+
#
|
20
|
+
def clear_cache
|
21
|
+
$redis.del redis_cache_settings[:redis_key_name]
|
22
|
+
end
|
23
|
+
|
24
|
+
end # << self
|
25
|
+
end # Base
|
26
|
+
end # ActionMailer
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Mail
|
2
|
+
#
|
3
|
+
# Performs deliveries to temporary cache file, so mails can accessed from
|
4
|
+
# other processes.
|
5
|
+
#
|
6
|
+
# Default location of files is:
|
7
|
+
# - "tmp/cache/action_mailer_cache_deliveries.cache" if you use Rails
|
8
|
+
# - "/tmp/cache/action_mailer_cache_deliveries.cache" if you don't use Rails
|
9
|
+
#
|
10
|
+
# However, you can overwrite location in configuration:
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# config.action_mailer.cache_settings = { location: "custom/path" }
|
14
|
+
#
|
15
|
+
class CacheDelivery
|
16
|
+
|
17
|
+
# @attr [Hash] settings Settings for CacheDelivery
|
18
|
+
attr_accessor :settings
|
19
|
+
|
20
|
+
# @api private
|
21
|
+
def initialize(settings)
|
22
|
+
@settings = settings
|
23
|
+
end
|
24
|
+
|
25
|
+
# @api private
|
26
|
+
def deliver!(mail)
|
27
|
+
list = Redis::List.new settings[:redis_key_name], :marshal => true
|
28
|
+
list << mail
|
29
|
+
end
|
30
|
+
|
31
|
+
end # CacheDelivery
|
32
|
+
end # Mail
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module RedisCacheMailerDelivery
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
|
4
|
+
#
|
5
|
+
# Make settings available before configuration:
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# config.action_mailer.delivery_method = :redis_cache
|
9
|
+
# config.action_mailer.cache_settings = { redis_key_name => "redis_cache_mailer_delivery:mail_messages" }
|
10
|
+
#
|
11
|
+
config.before_configuration do
|
12
|
+
RedisCacheMailerDelivery.install
|
13
|
+
end
|
14
|
+
|
15
|
+
end # Railtie
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/redis_cache_mailer_delivery/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Yi Wen"]
|
6
|
+
gem.email = ["hayafirst@gmail.com"]
|
7
|
+
gem.description = %q{Use Redis to store the Mail::Message when using in Rails}
|
8
|
+
gem.summary = %q{Use Redis to store the Mail::Message when using in Rails}
|
9
|
+
gem.homepage = "https://github.com/ywen/redis_cache_mailer_delivery"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "redis_cache_mailer_delivery"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = RedisCacheMailerDelivery::VERSION
|
17
|
+
gem.add_runtime_dependency(%q<redis>)
|
18
|
+
gem.add_runtime_dependency(%q<redis-objects>)
|
19
|
+
gem.add_runtime_dependency(%q<actionmailer>)
|
20
|
+
gem.add_development_dependency(%q<rspec>)
|
21
|
+
gem.add_development_dependency(%q<guard-rspectacle>)
|
22
|
+
gem.add_development_dependency(%q<growl>)
|
23
|
+
gem.add_development_dependency(%q<rb-fsevent>)
|
24
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
|
2
|
+
|
3
|
+
describe RedisCacheMailerDelivery do
|
4
|
+
describe ".install" do
|
5
|
+
it "adds a delivery method to the ActionMailer" do
|
6
|
+
described_class.install
|
7
|
+
ActionMailer::Base.delivery_methods.should include(:redis_cache => Mail::CacheDelivery)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Requires supporting files with custom matchers and macros, etc,
|
2
|
+
# in ./support/ and its subdirectories.
|
3
|
+
require 'rspec/core'
|
4
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
5
|
+
require "#{File.dirname(__FILE__)}/../lib/redis_cache_mailer_delivery"
|
6
|
+
Dir["#{File.dirname(__FILE__)}/../lib/**/*.rb"].each {|f| require f}
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
# == Mock Framework
|
10
|
+
#
|
11
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
12
|
+
#
|
13
|
+
# config.mock_with :mocha
|
14
|
+
# config.mock_with :flexmock
|
15
|
+
# config.mock_with :rr
|
16
|
+
config.mock_with :rspec
|
17
|
+
# out = ENV['CC_BUILD_ARTIFACTS'] || "#{Rails.root}"
|
18
|
+
# config.output_stream = File.open("#{out}/UnitTests/index.html", "w") if config.formatter_class.name =~ /HtmlFormatter/
|
19
|
+
|
20
|
+
|
21
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
22
|
+
# examples within a transaction, comment the following line or assign false
|
23
|
+
# instead of true.
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redis_cache_mailer_delivery
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Yi Wen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: redis
|
16
|
+
requirement: &70203010834820 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70203010834820
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: redis-objects
|
27
|
+
requirement: &70203010834180 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70203010834180
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: actionmailer
|
38
|
+
requirement: &70203010833380 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70203010833380
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: &70203010832580 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70203010832580
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: guard-rspectacle
|
60
|
+
requirement: &70203010831940 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70203010831940
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: growl
|
71
|
+
requirement: &70203010831400 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70203010831400
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: rb-fsevent
|
82
|
+
requirement: &70203010830820 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70203010830820
|
91
|
+
description: Use Redis to store the Mail::Message when using in Rails
|
92
|
+
email:
|
93
|
+
- hayafirst@gmail.com
|
94
|
+
executables: []
|
95
|
+
extensions: []
|
96
|
+
extra_rdoc_files: []
|
97
|
+
files:
|
98
|
+
- .gitignore
|
99
|
+
- .rspec
|
100
|
+
- .rvmrc
|
101
|
+
- Gemfile
|
102
|
+
- Guardfile
|
103
|
+
- LICENSE
|
104
|
+
- README.md
|
105
|
+
- Rakefile
|
106
|
+
- lib/redis_cache_mailer_delivery.rb
|
107
|
+
- lib/redis_cache_mailer_delivery/action_mailer/base.rb
|
108
|
+
- lib/redis_cache_mailer_delivery/mail/cache_delivery.rb
|
109
|
+
- lib/redis_cache_mailer_delivery/railtie.rb
|
110
|
+
- lib/redis_cache_mailer_delivery/version.rb
|
111
|
+
- redis_cache_mailer_delivery.gemspec
|
112
|
+
- spec/redis_cache_mailer_delivery_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
- spec/support/faked_rails.rb
|
115
|
+
homepage: https://github.com/ywen/redis_cache_mailer_delivery
|
116
|
+
licenses: []
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ! '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 1.8.17
|
136
|
+
signing_key:
|
137
|
+
specification_version: 3
|
138
|
+
summary: Use Redis to store the Mail::Message when using in Rails
|
139
|
+
test_files:
|
140
|
+
- spec/redis_cache_mailer_delivery_spec.rb
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
- spec/support/faked_rails.rb
|