merb_resque_mailer 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +52 -0
  2. data/lib/merb_resque_mailer.rb +40 -0
  3. metadata +65 -0
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ Merb Resque Mailer
2
+ ==================
3
+
4
+ Plugin for Merb which allows putting mail deliveries onto [Resque](http://github.com/defunkt/resque) queue.
5
+
6
+ Usage
7
+ -----
8
+
9
+ Include Resque::Mailer module in your Merb::MailController subclass(es) like this:
10
+
11
+ class UserMailer < Merb::MailController
12
+ include Resque::Mailer
13
+ ...
14
+ end
15
+
16
+ or directly in Merb::MailController class if you want to enable it for all mailers:
17
+
18
+ class Merb::MailController
19
+ include Resque::Mailer
20
+ ...
21
+ end
22
+
23
+ Jobs are added to "mailer" queue so you should start at least one worker listening on "mailer" queue:
24
+
25
+ QUEUE=mailer rake merb_env resque:work
26
+
27
+ From now on all emails will be sent asynchronously using Resque worker(s).
28
+
29
+ Installation
30
+ ------------
31
+
32
+ Gem is hosted on gemcutter.org, simply install it by:
33
+
34
+ gem install merb_resque_mailer
35
+
36
+ and require it in your app (or just add it bundler's Gemfile).
37
+
38
+ Configuration
39
+ -------------
40
+
41
+ You can configure for which environments you don't want to use Merb Resque Mailer by setting Resque::Mailer.excluded_environments option (by default :test env is excluded). If you want to exclude also :development env put following code somewhere in config/init.rb:
42
+ Resque::Mailer.excluded_environments = [:test, :development]
43
+
44
+ or
45
+
46
+ Resque::Mailer.excluded_environments << :development
47
+
48
+ Credits
49
+ -------
50
+
51
+ This piece of code was inspired by work of [Nick Plante](http://github.com/zapnap) who created [resque_mailer](http://github.com/zapnap/resque_mailer) for Rails' ActionMailer. Rewritten to work with Merb Mailer by [Marcin Kulik](http://github.com/sickill).
52
+
@@ -0,0 +1,40 @@
1
+ require 'resque'
2
+
3
+ module Resque
4
+ module Mailer
5
+
6
+ def self.excluded_environments=(*environments)
7
+ @@excluded_environments = environments && environments.flatten.collect! { |env| env.to_sym }
8
+ end
9
+
10
+ def self.excluded_environments
11
+ @@excluded_environments ||= [:test]
12
+ end
13
+
14
+ def self.included(base)
15
+ base.extend(ClassMethods)
16
+ base.class_eval do
17
+ alias_method :dispatch_and_deliver!, :dispatch_and_deliver
18
+
19
+ def dispatch_and_deliver(method, mail_params)
20
+ if ::Resque::Mailer.excluded_environments.include?(Merb.env.to_sym)
21
+ dispatch_and_deliver!(method, mail_params)
22
+ else
23
+ ::Resque.enqueue(self.class, @params, method, mail_params)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ module ClassMethods
30
+ def queue
31
+ :mailer
32
+ end
33
+
34
+ def perform(params, method, mail_params)
35
+ new(params).dispatch_and_deliver!(method, mail_params)
36
+ end
37
+ end
38
+
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: merb_resque_mailer
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Marcin Kulik
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-10 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: resque
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: marcin.kulik@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - lib/merb_resque_mailer.rb
35
+ - README.md
36
+ has_rdoc: true
37
+ homepage: http://sickill.net
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.5
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Merb plugin for putting mail delivery jobs onto Resque queue
64
+ test_files: []
65
+