email_prefixer 1.1.0 → 1.2.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b61b05c800103a57cec9350aaa65927affc4d587
4
- data.tar.gz: ce1f60d57950924b048d6f17d3919dcf5f461b95
3
+ metadata.gz: 0b59bd2b47776df5e37c07e9d81f38a2557ddb04
4
+ data.tar.gz: 8ea68d728900174530551ea886787eba0bfb5d87
5
5
  SHA512:
6
- metadata.gz: 4145cf9ded7b88ade8a6467f7616c88116c74af43055aa9ff732008def8aa1339a8dd74d59da279526c906f8b7fbd84d0a02ec0b9ae89023c3a705a4ae708234
7
- data.tar.gz: c6a2266d03a164ecbac1f405c553a6043efbd2f62fae69da4430162a7931a4b5b29f0ca02aa8809224516c3aeb740a3aeeaa741ff4bf3ee8767a4274861aa32f
6
+ metadata.gz: 86f4e57fc693f860c8d402a6011a38b24b0af52635a79ef2f1275b7a87f1652cce5754fd9d1408cf80df690eb792974b71ecbfce079b4e1e0f9151198b76a52a
7
+ data.tar.gz: 7699c6eb41d15f9f2b554af6e632f85762363899dfd397c71b7f0d61f7e62b22e7b66f2b391d82a70cafe3ba65636f05dc80267b86f802d442b5280a24365ffa
data/README.md CHANGED
@@ -63,6 +63,20 @@ EmailPrefixer.configure do |config|
63
63
  end
64
64
  ```
65
65
 
66
+ #### builder - Override the prefix format
67
+ Want to override the default format for the email prefix? Assign a custom
68
+ `proc` to the `builder` setting like so:
69
+
70
+ Example:
71
+ ```ruby
72
+ # config/initializers/email_prefixer.rb
73
+ EmailPrefixer.configure do |config|
74
+ config.builder = lambda do
75
+ '**MyEmailPrefix** '
76
+ end
77
+ end
78
+ ```
79
+
66
80
  ## Contributing
67
81
 
68
82
  1. Fork it ( https://github.com/wireframe/email_prefixer/fork )
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency 'rails', '>= 4.0'
22
22
 
23
- spec.add_development_dependency 'bundler', '~> 1.7'
24
- spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'bundler'
24
+ spec.add_development_dependency 'rake'
25
25
  spec.add_development_dependency 'sqlite3'
26
26
  spec.add_development_dependency 'rspec-rails'
27
27
  spec.add_development_dependency 'pry'
@@ -1,12 +1,13 @@
1
1
  require 'email_prefixer/version'
2
2
  require 'email_prefixer/configuration'
3
3
  require 'email_prefixer/interceptor'
4
- require 'email_prefixer/railtie'
4
+ require 'email_prefixer/railtie' if defined?(Rails)
5
5
 
6
6
  module EmailPrefixer
7
7
  class << self
8
8
  def configure
9
9
  yield configuration
10
+ configuration
10
11
  end
11
12
 
12
13
  def configuration
@@ -1,5 +1,12 @@
1
1
  module EmailPrefixer
2
2
  class Configuration
3
- attr_accessor :application_name, :stage_name
3
+ DEFAULT_BUILDER = lambda do
4
+ stage_name = EmailPrefixer.configuration.stage_name
5
+ prefixes = []
6
+ prefixes << EmailPrefixer.configuration.application_name
7
+ prefixes << stage_name.upcase unless stage_name == 'production'
8
+ "[#{prefixes.join(' ')}] "
9
+ end
10
+ attr_accessor :application_name, :stage_name, :builder
4
11
  end
5
12
  end
@@ -1,24 +1,15 @@
1
1
  module EmailPrefixer
2
2
  class Interceptor
3
- extend Forwardable
4
- def_delegators :@configuration, :application_name, :stage_name
3
+ attr_reader :configuration
5
4
 
6
- def initialize
7
- @configuration = EmailPrefixer.configuration
5
+ def initialize(configuration)
6
+ @configuration = configuration
8
7
  end
9
8
 
10
9
  def delivering_email(mail)
11
- mail.subject.prepend(subject_prefix)
10
+ prefix = configuration.builder.call
11
+ mail.subject.prepend(prefix)
12
12
  end
13
13
  alias_method :previewing_email, :delivering_email
14
-
15
- private
16
-
17
- def subject_prefix
18
- prefixes = []
19
- prefixes << application_name
20
- prefixes << stage_name.upcase unless stage_name == 'production'
21
- "[#{prefixes.join(' ')}] "
22
- end
23
14
  end
24
15
  end
@@ -1,13 +1,14 @@
1
1
  module EmailPrefixer
2
2
  class Railtie < ::Rails::Railtie
3
- initializer 'email_prefixer.configure_default_application_name' do |app|
4
- interceptor = EmailPrefixer::Interceptor.new
5
- ActionMailer::Base.register_preview_interceptor(interceptor)
6
- ActionMailer::Base.register_interceptor(interceptor)
7
- EmailPrefixer.configure do |config|
3
+ initializer 'email_prefixer.configure_defaults' do |app|
4
+ config = EmailPrefixer.configure do |config|
8
5
  config.application_name ||= app.class.parent_name
9
6
  config.stage_name ||= Rails.env
7
+ config.builder ||= EmailPrefixer::Configuration::DEFAULT_BUILDER
10
8
  end
9
+ interceptor = EmailPrefixer::Interceptor.new(config)
10
+ ActionMailer::Base.register_preview_interceptor(interceptor)
11
+ ActionMailer::Base.register_interceptor(interceptor)
11
12
  end
12
13
  end
13
14
  end
@@ -1,3 +1,3 @@
1
1
  module EmailPrefixer
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0.pre.1'
3
3
  end
@@ -0,0 +1,25 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe EmailPrefixer::Configuration do
4
+ before do
5
+ EmailPrefixer.configuration.application_name = 'MyApp'
6
+ end
7
+
8
+ describe EmailPrefixer::Configuration::DEFAULT_BUILDER do
9
+ describe '#call' do
10
+ subject { EmailPrefixer::Configuration::DEFAULT_BUILDER.call }
11
+ context 'when stage_name == production' do
12
+ before do
13
+ EmailPrefixer.configuration.stage_name = 'production'
14
+ end
15
+ it { is_expected.to eq '[MyApp] ' }
16
+ end
17
+ context 'when stage_name != production' do
18
+ before do
19
+ EmailPrefixer.configuration.stage_name = 'staging'
20
+ end
21
+ it { is_expected.to eq '[MyApp STAGING] ' }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -3,41 +3,15 @@ require 'rails_helper'
3
3
  RSpec.describe EmailPrefixer::Interceptor do
4
4
  describe '#delivering_email' do
5
5
  subject(:email) { ExampleMailer.simple_mail }
6
- context 'when application_name is configured' do
6
+ context 'when application_name and stage_name is configured' do
7
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
13
- end
14
-
15
- context 'when stage_name is configured' do
16
- before do
17
- @original_stage_name = EmailPrefixer.configuration.stage_name
8
+ EmailPrefixer.configuration.application_name = 'CustomApp'
18
9
  EmailPrefixer.configuration.stage_name = 'staging'
19
10
  email.deliver_now
20
11
  end
21
- after do
22
- EmailPrefixer.configuration.stage_name = @original_stage_name
23
- end
24
- it 'adds custom stage name to subject' do
12
+ it 'adds prefix to mail subject' do
25
13
  expect(email.subject).to eq '[CustomApp STAGING] Here is the Subject'
26
14
  end
27
15
  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
41
- end
42
16
  end
43
17
  end
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.1.0
4
+ version: 1.2.0.pre.1
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-21 00:00:00.000000000 Z
11
+ date: 2015-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -28,30 +28,30 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.7'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.7'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -156,7 +156,6 @@ files:
156
156
  - spec/dummy/config/initializers/assets.rb
157
157
  - spec/dummy/config/initializers/backtrace_silencers.rb
158
158
  - spec/dummy/config/initializers/cookies_serializer.rb
159
- - spec/dummy/config/initializers/email_prefixer.rb
160
159
  - spec/dummy/config/initializers/filter_parameter_logging.rb
161
160
  - spec/dummy/config/initializers/inflections.rb
162
161
  - spec/dummy/config/initializers/mime_types.rb
@@ -172,6 +171,7 @@ files:
172
171
  - spec/dummy/public/422.html
173
172
  - spec/dummy/public/500.html
174
173
  - spec/dummy/public/favicon.ico
174
+ - spec/lib/email_prefixer/configuration_spec.rb
175
175
  - spec/lib/email_prefixer/interceptor_spec.rb
176
176
  - spec/rails_helper.rb
177
177
  - spec/spec_helper.rb
@@ -190,12 +190,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
190
190
  version: '0'
191
191
  required_rubygems_version: !ruby/object:Gem::Requirement
192
192
  requirements:
193
- - - ">="
193
+ - - ">"
194
194
  - !ruby/object:Gem::Version
195
- version: '0'
195
+ version: 1.3.1
196
196
  requirements: []
197
197
  rubyforge_project:
198
- rubygems_version: 2.4.5
198
+ rubygems_version: 2.4.8
199
199
  signing_key:
200
200
  specification_version: 4
201
201
  summary: Automatically add email prefix to outgoing emails
@@ -229,7 +229,6 @@ test_files:
229
229
  - spec/dummy/config/initializers/assets.rb
230
230
  - spec/dummy/config/initializers/backtrace_silencers.rb
231
231
  - spec/dummy/config/initializers/cookies_serializer.rb
232
- - spec/dummy/config/initializers/email_prefixer.rb
233
232
  - spec/dummy/config/initializers/filter_parameter_logging.rb
234
233
  - spec/dummy/config/initializers/inflections.rb
235
234
  - spec/dummy/config/initializers/mime_types.rb
@@ -245,6 +244,7 @@ test_files:
245
244
  - spec/dummy/public/422.html
246
245
  - spec/dummy/public/500.html
247
246
  - spec/dummy/public/favicon.ico
247
+ - spec/lib/email_prefixer/configuration_spec.rb
248
248
  - spec/lib/email_prefixer/interceptor_spec.rb
249
249
  - spec/rails_helper.rb
250
250
  - spec/spec_helper.rb
@@ -1,4 +0,0 @@
1
- # override the default application name
2
- EmailPrefixer.configure do |config|
3
- config.application_name = 'CustomApp'
4
- end