multiple_mailers 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in multiple_mailers.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Richard Huang (flyerhzm@gmail.com)
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,53 @@
1
+ # MultipleMailers
2
+
3
+ extend actionmailer to allow one smtp account per mailer class.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'multiple_mailers'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install multiple_mailers
18
+
19
+ ## Usage
20
+
21
+ define your smtp mailer accounts in `config/mailers.yml`
22
+
23
+ default: &default
24
+ address: 'smtp.gmail.com'
25
+ port: 587
26
+ domain: 'railsbp.com'
27
+ authentication: 'plain'
28
+
29
+ notification:
30
+ <<: *default
31
+ user_name: 'notification@railsbp.com'
32
+ password: 'password'
33
+
34
+ exception.notifier:
35
+ <<: *default
36
+ user_name: 'exception.notifier@railsbp.com'
37
+ password: 'password'
38
+
39
+ the default account is used for all mailer classes, if you want to
40
+ override it, you can define mailer account for any mailer class you
41
+ want, like
42
+
43
+ class NotificationMailer < ActionMailer::Base
44
+ mailer_account "notification"
45
+ end
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,15 @@
1
+ require "yaml"
2
+
3
+ module MultipleMailers
4
+ class Configuration
5
+ class <<self
6
+ def load
7
+ @configurations ||= YAML.load_file(Rails.root.join("config/mailers.yml"))
8
+ end
9
+
10
+ def get(name)
11
+ @configurations and @configurations[name]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module MultipleMailers
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,33 @@
1
+ require "multiple_mailers/version"
2
+ require "yaml"
3
+ require "action_mailer"
4
+
5
+ module MultipleMailers
6
+ autoload :Configuration, "multiple_mailers/configuration"
7
+
8
+ def self.included(base)
9
+ base.extend(ClassMethods)
10
+ base.class_eval do
11
+ Configuration.load
12
+ mailer_account("default")
13
+ end
14
+ end
15
+
16
+ if defined? Rails::Railtie
17
+ class BulletRailtie < Rails::Railtie
18
+ initializer "multiple_mailers.configure_rails_initialization" do |app|
19
+ ActionMailer::Base.send(:include, MultipleMailers)
20
+ end
21
+ end
22
+ end
23
+
24
+ module ClassMethods
25
+ def mailer_account(name)
26
+ config = Configuration.get(name)
27
+ if config
28
+ self.smtp_settings = config.symbolize_keys
29
+ end
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/multiple_mailers/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Richard Huang"]
6
+ gem.email = ["flyerhzm@gmail.com"]
7
+ gem.description = %q{extend actionmailer to allow one smtp account per mailer class}
8
+ gem.summary = %q{extend actionmailer to allow one smtp account per mailer class}
9
+ gem.homepage = "https://github.com/flyerhzm/multiple_mailers"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "multiple_mailers"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = MultipleMailers::VERSION
17
+
18
+ gem.add_development_dependency "actionmailer"
19
+ end
@@ -0,0 +1,15 @@
1
+ default: &default
2
+ address: 'smtp.gmail.com'
3
+ port: 587
4
+ domain: 'railsbp.com'
5
+ authentication: 'plain'
6
+
7
+ notification:
8
+ <<: *default
9
+ user_name: 'notification@railsbp.com'
10
+ password: 'password'
11
+
12
+ exception.notifier:
13
+ <<: *default
14
+ user_name: 'exception.notifier@railsbp.com'
15
+ password: 'password'
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ module MultipleMailers
4
+ describe Configuration do
5
+ context ".load" do
6
+ it "should read config/mailers.yml" do
7
+ Configuration.load
8
+ Configuration.instance_variable_get(:@configurations).should_not be_empty
9
+ end
10
+ end
11
+
12
+ context ".get" do
13
+ before { Configuration.load }
14
+
15
+ it "should get configuration for notification" do
16
+ config = Configuration.get("notification")
17
+ config["address"].should == "smtp.gmail.com"
18
+ config["port"].should == 587
19
+ config["domain"].should == "railsbp.com"
20
+ config["authentication"].should == "plain"
21
+ config["user_name"].should == "notification@railsbp.com"
22
+ config["password"].should == "password"
23
+ end
24
+
25
+ it "should get configuration for exception_notifier" do
26
+ config = Configuration.get("exception.notifier")
27
+ config["address"].should == "smtp.gmail.com"
28
+ config["port"].should == 587
29
+ config["domain"].should == "railsbp.com"
30
+ config["authentication"].should == "plain"
31
+ config["user_name"].should == "exception.notifier@railsbp.com"
32
+ config["password"].should == "password"
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe MultipleMailers do
4
+ context ".mail_account" do
5
+ before { ActionMailer::Base.send(:include, MultipleMailers) }
6
+
7
+ it "should set default configuration" do
8
+ default_config = ActionMailer::Base.smtp_settings
9
+ default_config[:address].should == "smtp.gmail.com"
10
+ default_config[:port].should == 587
11
+ default_config[:domain].should == "railsbp.com"
12
+ default_config[:authentication].should == "plain"
13
+ default_config[:user_name].should be_nil
14
+ default_config[:password].should be_nil
15
+ end
16
+
17
+ it "should set notification configuration" do
18
+ ActionMailer::Base.class_eval { mailer_account "notification" }
19
+ default_config = ActionMailer::Base.smtp_settings
20
+ default_config[:address].should == "smtp.gmail.com"
21
+ default_config[:port].should == 587
22
+ default_config[:domain].should == "railsbp.com"
23
+ default_config[:authentication].should == "plain"
24
+ default_config[:user_name].should == "notification@railsbp.com"
25
+ default_config[:password].should == "password"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,9 @@
1
+ require 'rspec'
2
+
3
+ class Rails
4
+ def self.root
5
+ Pathname.new(__FILE__).dirname
6
+ end
7
+ end
8
+
9
+ require 'multiple_mailers'
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: multiple_mailers
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Richard Huang
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: actionmailer
16
+ requirement: &70167355381020 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70167355381020
25
+ description: extend actionmailer to allow one smtp account per mailer class
26
+ email:
27
+ - flyerhzm@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - lib/multiple_mailers.rb
38
+ - lib/multiple_mailers/configuration.rb
39
+ - lib/multiple_mailers/version.rb
40
+ - multiple_mailers.gemspec
41
+ - spec/config/mailers.yml
42
+ - spec/multiple_mailers/configuration_spec.rb
43
+ - spec/multiple_mailers_spec.rb
44
+ - spec/spec_helper.rb
45
+ homepage: https://github.com/flyerhzm/multiple_mailers
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.17
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: extend actionmailer to allow one smtp account per mailer class
69
+ test_files:
70
+ - spec/config/mailers.yml
71
+ - spec/multiple_mailers/configuration_spec.rb
72
+ - spec/multiple_mailers_spec.rb
73
+ - spec/spec_helper.rb