Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

first commit

  • Loading branch information...
commit bf8ce82fafa4f7c31ee65c97e7baf7212e927e7e 0 parents
ywen2 ywen2 authored
17 .gitignore
... ... @@ -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
4 Gemfile
... ... @@ -0,0 +1,4 @@
  1 +source 'https://rubygems.org'
  2 +
  3 +# Specify your gem's dependencies in redis_cache_mailer_delivery.gemspec
  4 +gemspec
22 LICENSE
... ... @@ -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.
29 README.md
Source Rendered
... ... @@ -0,0 +1,29 @@
  1 +# RedisCacheMailerDelivery
  2 +
  3 +TODO: Write a gem description
  4 +
  5 +## Installation
  6 +
  7 +Add this line to your application's Gemfile:
  8 +
  9 + gem 'redis_cache_mailer_delivery'
  10 +
  11 +And then execute:
  12 +
  13 + $ bundle
  14 +
  15 +Or install it yourself as:
  16 +
  17 + $ gem install redis_cache_mailer_delivery
  18 +
  19 +## Usage
  20 +
  21 +TODO: Write usage instructions here
  22 +
  23 +## Contributing
  24 +
  25 +1. Fork it
  26 +2. Create your feature branch (`git checkout -b my-new-feature`)
  27 +3. Commit your changes (`git commit -am 'Added some feature'`)
  28 +4. Push to the branch (`git push origin my-new-feature`)
  29 +5. Create new Pull Request
2  Rakefile
... ... @@ -0,0 +1,2 @@
  1 +#!/usr/bin/env rake
  2 +require "bundler/gem_tasks"
15 lib/redis_cache_mailer_delivery.rb
... ... @@ -0,0 +1,15 @@
  1 +require 'redis_cache_mailer_delivery/version'
  2 +require 'redis_cache_mailer_delivery/mail/cache_delivery'
  3 +require 'redis_cache_mailer_delivery/action_mailer/base'
  4 +
  5 +module RedisCacheMailerDelivery
  6 + class << self
  7 + def install
  8 + ActionMailer::Base.add_delivery_method :redis_cache, Mail::CacheDelivery,
  9 + :redis_key_name => "redis_cache_mailer_delivery:mail_messages"
  10 + end
  11 +
  12 + end # << self
  13 +end # RedisCacheMailerDelivery
  14 +require 'redis_cache_mailer_delivery/railtie' if defined?(Rails)
  15 +require "redis_cache_mailer_delivery/version"
26 lib/redis_cache_mailer_delivery/action_mailer/base.rb
... ... @@ -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
32 lib/redis_cache_mailer_delivery/mail/cache_delivery.rb
... ... @@ -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
16 lib/redis_cache_mailer_delivery/railtie.rb
... ... @@ -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 = :cache
  9 + # config.action_mailer.cache_settings = { location: "#{Rails.root}/tmp/mail.cache" }
  10 + #
  11 + config.before_configuration do
  12 + ActionMailerCacheDelivery.install
  13 + end
  14 +
  15 + end # Railtie
  16 +end
3  lib/redis_cache_mailer_delivery/version.rb
... ... @@ -0,0 +1,3 @@
  1 +module RedisCacheMailerDelivery
  2 + VERSION = "0.0.1"
  3 +end
19 redis_cache_mailer_delivery.gemspec
... ... @@ -0,0 +1,19 @@
  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-rb>)
  18 + gem.add_runtime_dependency(%q<redis-objects>)
  19 +end

0 comments on commit bf8ce82

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