email_prefixer 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -5
- data/lib/email_prefixer/configuration.rb +1 -1
- data/lib/email_prefixer/interceptor.rb +9 -2
- data/lib/email_prefixer/railtie.rb +1 -0
- data/lib/email_prefixer/version.rb +1 -1
- data/spec/lib/email_prefixer/interceptor_spec.rb +35 -5
- data/spec/spec_helper.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b61b05c800103a57cec9350aaa65927affc4d587
|
4
|
+
data.tar.gz: ce1f60d57950924b048d6f17d3919dcf5f461b95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4145cf9ded7b88ade8a6467f7616c88116c74af43055aa9ff732008def8aa1339a8dd74d59da279526c906f8b7fbd84d0a02ec0b9ae89023c3a705a4ae708234
|
7
|
+
data.tar.gz: c6a2266d03a164ecbac1f405c553a6043efbd2f62fae69da4430162a7931a4b5b29f0ca02aa8809224516c3aeb740a3aeeaa741ff4bf3ee8767a4274861aa32f
|
data/README.md
CHANGED
@@ -25,17 +25,41 @@ gem 'email_prefixer'
|
|
25
25
|
```
|
26
26
|
|
27
27
|
## Configuration
|
28
|
+
All EmailPrefixer configuration can be customized using
|
29
|
+
a standard Rails config initializer.
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
```ruby
|
32
|
+
# config/initializers/email_prefixer.rb
|
33
|
+
EmailPrefixer.configure do |config|
|
34
|
+
# custom configuration goes here
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
Some of the more common configuration options are listed here.
|
39
|
+
See the source code and test suite for a full list of options.
|
40
|
+
|
41
|
+
#### application_name - Customize Application Name
|
42
|
+
The application name is automatically inferred from the Rails application class name
|
43
|
+
and can be overridden via the `application_name` setting.
|
44
|
+
|
45
|
+
Example:
|
46
|
+
```ruby
|
47
|
+
# config/initializers/email_prefixer.rb
|
48
|
+
EmailPrefixer.configure do |config|
|
49
|
+
config.application_name = 'MyApp'
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
#### stage_name - Customize Environment Stage Name
|
54
|
+
The application environment/stage name is automatically
|
55
|
+
inferred from the running Rails.env and it can be overridden
|
56
|
+
via the `stage_name` setting.
|
33
57
|
|
34
58
|
Example:
|
35
59
|
```ruby
|
36
60
|
# config/initializers/email_prefixer.rb
|
37
61
|
EmailPrefixer.configure do |config|
|
38
|
-
config.
|
62
|
+
config.stage_name = 'demo'
|
39
63
|
end
|
40
64
|
```
|
41
65
|
|
@@ -1,5 +1,12 @@
|
|
1
1
|
module EmailPrefixer
|
2
2
|
class Interceptor
|
3
|
+
extend Forwardable
|
4
|
+
def_delegators :@configuration, :application_name, :stage_name
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@configuration = EmailPrefixer.configuration
|
8
|
+
end
|
9
|
+
|
3
10
|
def delivering_email(mail)
|
4
11
|
mail.subject.prepend(subject_prefix)
|
5
12
|
end
|
@@ -9,8 +16,8 @@ module EmailPrefixer
|
|
9
16
|
|
10
17
|
def subject_prefix
|
11
18
|
prefixes = []
|
12
|
-
prefixes <<
|
13
|
-
prefixes <<
|
19
|
+
prefixes << application_name
|
20
|
+
prefixes << stage_name.upcase unless stage_name == 'production'
|
14
21
|
"[#{prefixes.join(' ')}] "
|
15
22
|
end
|
16
23
|
end
|
@@ -2,12 +2,42 @@ require 'rails_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe EmailPrefixer::Interceptor do
|
4
4
|
describe '#delivering_email' do
|
5
|
-
|
6
|
-
|
5
|
+
subject(:email) { ExampleMailer.simple_mail }
|
6
|
+
context 'when application_name is configured' do
|
7
|
+
before do
|
8
|
+
email.deliver_now
|
9
|
+
end
|
10
|
+
it 'adds prefix to delivered mail subject' do
|
11
|
+
expect(email.subject).to eq '[CustomApp TEST] Here is the Subject'
|
12
|
+
end
|
7
13
|
end
|
8
|
-
|
9
|
-
|
10
|
-
|
14
|
+
|
15
|
+
context 'when stage_name is configured' do
|
16
|
+
before do
|
17
|
+
@original_stage_name = EmailPrefixer.configuration.stage_name
|
18
|
+
EmailPrefixer.configuration.stage_name = 'staging'
|
19
|
+
email.deliver_now
|
20
|
+
end
|
21
|
+
after do
|
22
|
+
EmailPrefixer.configuration.stage_name = @original_stage_name
|
23
|
+
end
|
24
|
+
it 'adds custom stage name to subject' do
|
25
|
+
expect(email.subject).to eq '[CustomApp STAGING] Here is the Subject'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when stage_name == production' do
|
30
|
+
before do
|
31
|
+
@original_stage_name = EmailPrefixer.configuration.stage_name
|
32
|
+
EmailPrefixer.configuration.stage_name = 'production'
|
33
|
+
email.deliver_now
|
34
|
+
end
|
35
|
+
after do
|
36
|
+
EmailPrefixer.configuration.stage_name = @original_stage_name
|
37
|
+
end
|
38
|
+
it 'does not add the stage_name to the subject' do
|
39
|
+
expect(email.subject).to eq '[CustomApp] Here is the Subject'
|
40
|
+
end
|
11
41
|
end
|
12
42
|
end
|
13
43
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: email_prefixer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Sonnek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|