catch_all 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b9ecfda75b7a73bcb32ada1f5e876e4e03e23a93
4
+ data.tar.gz: facd9a247bbc4416f5ad83df7442439f5174dfbe
5
+ SHA512:
6
+ metadata.gz: 0d8821cf46adab5a2b268cdf5bcca4c3bec692ea04a3096fa4a96e857ea65280f6a6ad521fdcedd38b1831198ab10d8d10ea368013911935cef7402bab0c792b
7
+ data.tar.gz: 11afad6bec26b7c9c70ce4c6730a4fe1da9855c16ed0491ab4c772480299d54eabf8250b370a67d95c7fb3cfbde23c65f49360a5f707f49ed7ba4f30737d7616
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  *.gem
2
2
  .DS_Store
3
- .tmproj
3
+ .tmproj
4
+ .byebug_history
data/Gemfile CHANGED
@@ -6,4 +6,6 @@ gem 'actionmailer'
6
6
  group :development do
7
7
  gem 'rspec', '>= 2.3.0'
8
8
  gem 'ZenTest', "~> 4.4.2"
9
- end
9
+ gem 'byebug', platform: :mri
10
+ gem 'pry-byebug', platform: :mri
11
+ end
data/Gemfile.lock CHANGED
@@ -1,66 +1,91 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- catch_all (0.0.1)
4
+ catch_all (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ZenTest (4.4.2)
10
- actionmailer (3.2.11)
11
- actionpack (= 3.2.11)
12
- mail (~> 2.4.4)
13
- actionpack (3.2.11)
14
- activemodel (= 3.2.11)
15
- activesupport (= 3.2.11)
16
- builder (~> 3.0.0)
17
- erubis (~> 2.7.0)
18
- journey (~> 1.0.4)
19
- rack (~> 1.4.0)
20
- rack-cache (~> 1.2)
21
- rack-test (~> 0.6.1)
22
- sprockets (~> 2.2.1)
23
- activemodel (3.2.11)
24
- activesupport (= 3.2.11)
25
- builder (~> 3.0.0)
26
- activesupport (3.2.11)
27
- i18n (~> 0.6)
28
- multi_json (~> 1.0)
29
- builder (3.0.4)
30
- diff-lcs (1.1.3)
31
- erubis (2.7.0)
32
- hike (1.2.1)
33
- i18n (0.6.1)
34
- journey (1.0.4)
35
- mail (2.4.4)
36
- i18n (>= 0.4.0)
37
- mime-types (~> 1.16)
38
- treetop (~> 1.4.8)
39
- mime-types (1.19)
40
- multi_json (1.5.0)
41
- polyglot (0.3.3)
42
- rack (1.4.3)
43
- rack-cache (1.2)
44
- rack (>= 0.4)
45
- rack-test (0.6.2)
46
- rack (>= 1.0)
47
- rspec (2.12.0)
48
- rspec-core (~> 2.12.0)
49
- rspec-expectations (~> 2.12.0)
50
- rspec-mocks (~> 2.12.0)
51
- rspec-core (2.12.0)
52
- rspec-expectations (2.12.0)
53
- diff-lcs (~> 1.1.3)
54
- rspec-mocks (2.12.0)
55
- sprockets (2.2.2)
56
- hike (~> 1.2)
57
- multi_json (~> 1.0)
58
- rack (~> 1.0)
59
- tilt (~> 1.1, != 1.3.0)
60
- tilt (1.3.3)
61
- treetop (1.4.12)
62
- polyglot
63
- polyglot (>= 0.3.1)
10
+ actionmailer (5.2.0)
11
+ actionpack (= 5.2.0)
12
+ actionview (= 5.2.0)
13
+ activejob (= 5.2.0)
14
+ mail (~> 2.5, >= 2.5.4)
15
+ rails-dom-testing (~> 2.0)
16
+ actionpack (5.2.0)
17
+ actionview (= 5.2.0)
18
+ activesupport (= 5.2.0)
19
+ rack (~> 2.0)
20
+ rack-test (>= 0.6.3)
21
+ rails-dom-testing (~> 2.0)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
23
+ actionview (5.2.0)
24
+ activesupport (= 5.2.0)
25
+ builder (~> 3.1)
26
+ erubi (~> 1.4)
27
+ rails-dom-testing (~> 2.0)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
29
+ activejob (5.2.0)
30
+ activesupport (= 5.2.0)
31
+ globalid (>= 0.3.6)
32
+ activesupport (5.2.0)
33
+ concurrent-ruby (~> 1.0, >= 1.0.2)
34
+ i18n (>= 0.7, < 2)
35
+ minitest (~> 5.1)
36
+ tzinfo (~> 1.1)
37
+ builder (3.2.3)
38
+ byebug (10.0.2)
39
+ coderay (1.1.2)
40
+ concurrent-ruby (1.0.5)
41
+ crass (1.0.4)
42
+ diff-lcs (1.3)
43
+ erubi (1.7.1)
44
+ globalid (0.4.1)
45
+ activesupport (>= 4.2.0)
46
+ i18n (1.0.1)
47
+ concurrent-ruby (~> 1.0)
48
+ loofah (2.2.2)
49
+ crass (~> 1.0.2)
50
+ nokogiri (>= 1.5.9)
51
+ mail (2.7.0)
52
+ mini_mime (>= 0.1.1)
53
+ method_source (0.9.0)
54
+ mini_mime (1.0.0)
55
+ mini_portile2 (2.3.0)
56
+ minitest (5.11.3)
57
+ nokogiri (1.8.2)
58
+ mini_portile2 (~> 2.3.0)
59
+ pry (0.11.3)
60
+ coderay (~> 1.1.0)
61
+ method_source (~> 0.9.0)
62
+ pry-byebug (3.6.0)
63
+ byebug (~> 10.0)
64
+ pry (~> 0.10)
65
+ rack (2.0.5)
66
+ rack-test (1.0.0)
67
+ rack (>= 1.0, < 3)
68
+ rails-dom-testing (2.0.3)
69
+ activesupport (>= 4.2.0)
70
+ nokogiri (>= 1.6)
71
+ rails-html-sanitizer (1.0.4)
72
+ loofah (~> 2.2, >= 2.2.2)
73
+ rspec (3.7.0)
74
+ rspec-core (~> 3.7.0)
75
+ rspec-expectations (~> 3.7.0)
76
+ rspec-mocks (~> 3.7.0)
77
+ rspec-core (3.7.1)
78
+ rspec-support (~> 3.7.0)
79
+ rspec-expectations (3.7.0)
80
+ diff-lcs (>= 1.2.0, < 2.0)
81
+ rspec-support (~> 3.7.0)
82
+ rspec-mocks (3.7.0)
83
+ diff-lcs (>= 1.2.0, < 2.0)
84
+ rspec-support (~> 3.7.0)
85
+ rspec-support (3.7.1)
86
+ thread_safe (0.3.6)
87
+ tzinfo (1.2.5)
88
+ thread_safe (~> 0.1)
64
89
 
65
90
  PLATFORMS
66
91
  ruby
@@ -68,5 +93,10 @@ PLATFORMS
68
93
  DEPENDENCIES
69
94
  ZenTest (~> 4.4.2)
70
95
  actionmailer
96
+ byebug
71
97
  catch_all!
98
+ pry-byebug
72
99
  rspec (>= 2.3.0)
100
+
101
+ BUNDLED WITH
102
+ 1.16.1
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ActionMailer::CatchAll is a simple module to define a white-list of email addresses, used for staging environments.
4
4
 
5
+ If the emailed user is on the whitelist, it sends to that user.
6
+
7
+ If the user isn't on the whitelist, it sends to the fallback email address(es).
8
+
5
9
  ## Usage
6
10
 
7
11
  Gemfile:
@@ -14,4 +18,11 @@ ActionMailer::CatchAll is a simple module to define a white-list of email addres
14
18
  ActionMailer::CatchAll.enable('scott@railsnewbie.com')
15
19
  end
16
20
 
21
+ Or, if you want to use a whitelist of domains:
17
22
 
23
+ if Rails.env.staging?
24
+ ActionMailer::CatchAll.enable({
25
+ whitelist: [/\@railsnewbie.com$/, /\@example.com$/],
26
+ fallback: 'scott@railsnewbie.com',
27
+ })
28
+ end
@@ -1,5 +1,5 @@
1
1
  module ActionMailer
2
2
  module CatchAll
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
5
- end
5
+ end
data/lib/catch_all.rb CHANGED
@@ -8,10 +8,18 @@ module ActionMailer
8
8
  ActionMailer::Base.instance_methods.include?(:mail_aliased_from_action_mailer_staging)
9
9
  end
10
10
 
11
- def enable(*to_addresses)
12
- to_addresses = to_addresses.flatten.compact
11
+ def enable(*options)
12
+ if options.length == 1 && options[0].is_a?(Hash)
13
+ hash = options[0]
13
14
 
14
- if to_addresses.length == 0
15
+ whitelist_email_addresses = Array(hash[:whitelist]).flatten.compact
16
+ fallback_email_addresses = Array(hash[:fallback]).flatten.compact
17
+ else
18
+ whitelist_email_addresses = options.flatten.compact
19
+ fallback_email_addresses = whitelist_email_addresses
20
+ end
21
+
22
+ if fallback_email_addresses.length == 0
15
23
  Kernel.warn("No email addresses passed to ActionMailer::CatchAll!")
16
24
  end
17
25
 
@@ -31,11 +39,21 @@ module ActionMailer
31
39
 
32
40
  # save the original to header
33
41
  mailer['X-Action-Mailer-Staging-Original-Email-To'] = to_values.inspect
34
- selected_to_addresses = to_values.select { |to| to_addresses.include?(to) }
42
+
43
+ selected_to_addresses = to_values.select do |to|
44
+ whitelist_email_addresses.any? do |email|
45
+ if email.is_a?(Regexp)
46
+ email =~ to
47
+ else
48
+ email == to
49
+ end
50
+ end
51
+ end
52
+
35
53
  if selected_to_addresses.any?
36
54
  mailer[:to] = selected_to_addresses
37
55
  else
38
- mailer[:to] = to_addresses
56
+ mailer[:to] = fallback_email_addresses
39
57
  end
40
58
 
41
59
  mailer
@@ -53,4 +71,4 @@ module ActionMailer
53
71
  end
54
72
  end
55
73
  end
56
- end
74
+ end
@@ -1,24 +1,24 @@
1
- require File.dirname(__FILE__) + '/../lib/catch_all'
1
+ require 'spec_helper'
2
2
 
3
3
  class Notifier < ActionMailer::Base
4
4
  def notify
5
- mail(:to => "scott@learnup.me")
5
+ mail(:to => "scott@learnup.me", body: "body")
6
6
  end
7
7
 
8
8
  def notify_multiple
9
- mail(:to => ["scott@learnup.me", "kenny@learnup.me"])
9
+ mail(:to => ["scott@learnup.me", "kenny@learnup.me"], body: "body")
10
10
  end
11
11
 
12
12
  def notify_with_name
13
- mail(:to => "Scott Taylor <scott@learnup.me>")
13
+ mail(:to => "Scott Taylor <scott@learnup.me>", body: "body")
14
14
  end
15
15
 
16
16
  def notify_no_address
17
- mail()
17
+ mail(body: "body")
18
18
  end
19
19
 
20
20
  def notify_with_empty_to
21
- mail(:to => [])
21
+ mail(:to => [], body: "body")
22
22
  end
23
23
  end
24
24
 
@@ -118,4 +118,16 @@ describe ActionMailer::CatchAll do
118
118
  mailer = Notifier.notify
119
119
  mailer.to.should == []
120
120
  end
121
- end
121
+
122
+ it "should work with a whitelist regex" do
123
+ ActionMailer::CatchAll.enable(fallback: 'fallback@example.com', whitelist: [/\@learnup.me$/])
124
+ mailer = Notifier.notify
125
+ mailer.to.should == ["scott@learnup.me"]
126
+ end
127
+
128
+ it "should work with a fallback" do
129
+ ActionMailer::CatchAll.enable(fallback: 'fallback@example.com')
130
+ mailer = Notifier.notify
131
+ mailer.to.should == ["fallback@example.com"]
132
+ end
133
+ end
@@ -0,0 +1,12 @@
1
+ require 'byebug'
2
+ require File.dirname(__FILE__) + '/../lib/catch_all'
3
+
4
+ RSpec.configure do |config|
5
+ config.expect_with(:rspec) do |c|
6
+ c.syntax = :should
7
+ end
8
+
9
+ config.mock_with :rspec do |mocks|
10
+ mocks.syntax = :should
11
+ end
12
+ end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catch_all
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Scott Taylor
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-06 00:00:00.000000000 Z
11
+ date: 2018-06-12 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Define a white-list only set of emails for ActionMailer
15
14
  email:
@@ -18,8 +17,8 @@ executables: []
18
17
  extensions: []
19
18
  extra_rdoc_files: []
20
19
  files:
21
- - .gitignore
22
- - .rspec
20
+ - ".gitignore"
21
+ - ".rspec"
23
22
  - Gemfile
24
23
  - Gemfile.lock
25
24
  - README.md
@@ -27,30 +26,31 @@ files:
27
26
  - lib/catch_all.rb
28
27
  - lib/catch_all/version.rb
29
28
  - spec/catch_all_spec.rb
29
+ - spec/spec_helper.rb
30
30
  homepage: ''
31
31
  licenses: []
32
+ metadata: {}
32
33
  post_install_message:
33
34
  rdoc_options: []
34
35
  require_paths:
35
36
  - lib
36
37
  required_ruby_version: !ruby/object:Gem::Requirement
37
- none: false
38
38
  requirements:
39
- - - ! '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  required_rubygems_version: !ruby/object:Gem::Requirement
43
- none: false
44
43
  requirements:
45
- - - ! '>='
44
+ - - ">="
46
45
  - !ruby/object:Gem::Version
47
46
  version: '0'
48
47
  requirements: []
49
48
  rubyforge_project:
50
- rubygems_version: 1.8.24
49
+ rubygems_version: 2.6.14
51
50
  signing_key:
52
- specification_version: 3
51
+ specification_version: 4
53
52
  summary: Define a white-list only set of emails for ActionMailer. Used in staging
54
53
  environments.
55
54
  test_files:
56
55
  - spec/catch_all_spec.rb
56
+ - spec/spec_helper.rb