Skip to content
Browse files

first commit

  • Loading branch information...
0 parents commit bf8ce82fafa4f7c31ee65c97e7baf7212e927e7e @ywen2 ywen2 committed Mar 20, 2012
17 .gitignore
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
4 Gemfile
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in redis_cache_mailer_delivery.gemspec
+gemspec
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Yi Wen
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 README.md
@@ -0,0 +1,29 @@
+# RedisCacheMailerDelivery
+
+TODO: Write a gem description
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+ gem 'redis_cache_mailer_delivery'
+
+And then execute:
+
+ $ bundle
+
+Or install it yourself as:
+
+ $ gem install redis_cache_mailer_delivery
+
+## Usage
+
+TODO: Write usage instructions here
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Added some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
2 Rakefile
@@ -0,0 +1,2 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
15 lib/redis_cache_mailer_delivery.rb
@@ -0,0 +1,15 @@
+require 'redis_cache_mailer_delivery/version'
+require 'redis_cache_mailer_delivery/mail/cache_delivery'
+require 'redis_cache_mailer_delivery/action_mailer/base'
+
+module RedisCacheMailerDelivery
+ class << self
+ def install
+ ActionMailer::Base.add_delivery_method :redis_cache, Mail::CacheDelivery,
+ :redis_key_name => "redis_cache_mailer_delivery:mail_messages"
+ end
+
+ end # << self
+end # RedisCacheMailerDelivery
+require 'redis_cache_mailer_delivery/railtie' if defined?(Rails)
+require "redis_cache_mailer_delivery/version"
26 lib/redis_cache_mailer_delivery/action_mailer/base.rb
@@ -0,0 +1,26 @@
+module ActionMailer
+ class Base
+ class << self
+
+ #
+ # Returns an array of delivered mails.
+ #
+ # @return [Array] array of mails (each mail is an instance of Mail.)
+ #
+ def cached_deliveries
+ list = Redis::List.new redis_cache_settings[:redis_key_name], :marshal => true
+ list.values.map{|m|Marshal.load(m)}
+ end
+
+ #
+ # Clears delivered mails.
+ #
+ # It also cleans ActionMailer::Base.deliveries
+ #
+ def clear_cache
+ $redis.del redis_cache_settings[:redis_key_name]
+ end
+
+ end # << self
+ end # Base
+end # ActionMailer
32 lib/redis_cache_mailer_delivery/mail/cache_delivery.rb
@@ -0,0 +1,32 @@
+module Mail
+ #
+ # Performs deliveries to temporary cache file, so mails can accessed from
+ # other processes.
+ #
+ # Default location of files is:
+ # - "tmp/cache/action_mailer_cache_deliveries.cache" if you use Rails
+ # - "/tmp/cache/action_mailer_cache_deliveries.cache" if you don't use Rails
+ #
+ # However, you can overwrite location in configuration:
+ #
+ # @example
+ # config.action_mailer.cache_settings = { location: "custom/path" }
+ #
+ class CacheDelivery
+
+ # @attr [Hash] settings Settings for CacheDelivery
+ attr_accessor :settings
+
+ # @api private
+ def initialize(settings)
+ @settings = settings
+ end
+
+ # @api private
+ def deliver!(mail)
+ list = Redis::List.new settings[:redis_key_name], :marshal => true
+ list << mail
+ end
+
+ end # CacheDelivery
+end # Mail
16 lib/redis_cache_mailer_delivery/railtie.rb
@@ -0,0 +1,16 @@
+module RedisCacheMailerDelivery
+ class Railtie < Rails::Railtie
+
+ #
+ # Make settings available before configuration:
+ #
+ # @example
+ # config.action_mailer.delivery_method = :cache
+ # config.action_mailer.cache_settings = { location: "#{Rails.root}/tmp/mail.cache" }
+ #
+ config.before_configuration do
+ ActionMailerCacheDelivery.install
+ end
+
+ end # Railtie
+end
3 lib/redis_cache_mailer_delivery/version.rb
@@ -0,0 +1,3 @@
+module RedisCacheMailerDelivery
+ VERSION = "0.0.1"
+end
19 redis_cache_mailer_delivery.gemspec
@@ -0,0 +1,19 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/redis_cache_mailer_delivery/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Yi Wen"]
+ gem.email = ["hayafirst@gmail.com"]
+ gem.description = %q{Use Redis to store the Mail::Message when using in Rails}
+ gem.summary = %q{Use Redis to store the Mail::Message when using in Rails}
+ gem.homepage = "https://github.com/ywen/redis_cache_mailer_delivery"
+
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ gem.files = `git ls-files`.split("\n")
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ gem.name = "redis_cache_mailer_delivery"
+ gem.require_paths = ["lib"]
+ gem.version = RedisCacheMailerDelivery::VERSION
+ gem.add_runtime_dependency(%q<redis-rb>)
+ gem.add_runtime_dependency(%q<redis-objects>)
+end

0 comments on commit bf8ce82

Please sign in to comment.
Something went wrong with that request. Please try again.