roda-mailer_ext 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8dd5819628c0cdd98aa1ba6d494d0703afddb332
4
+ data.tar.gz: bc0d720572692281273cbf4d21f447f83b47fdfb
5
+ SHA512:
6
+ metadata.gz: d53cedf87191c1163e78ce3af26a77728f6d86492ca913d6c9e956de6f9bb7faa948167fbd3c92e2646a1b507561cab80e05071de046cc29041864e5063b1295
7
+ data.tar.gz: c2d7424846f6c6570cb13743abf942059eb2378efd347c1feb657406a840bfadba0668c0225999cc5f7d2e1bf388176e1bb7fd0796fc7eebfff9ce31ac047fa9
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Roda Mailer Extensions
2
+
3
+ A few helpful extensions to the Roda mailer plugin.
4
+
5
+ ## Installation
6
+
7
+ Add this line ot your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "roda-mailer_ext"
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install roda-mailer_ext
20
+
21
+ ## Usage
22
+
23
+ Simply configure this plugin as you would any other plugin. Without any options,
24
+ the plugin is a no-op. You will want to use the `log` or `prevent_delivery` options
25
+ to make the plugin useful.
26
+
27
+ I like to pair this plugin with the [environments](http://roda.jeremyevans.net/rdoc/classes/Roda/RodaPlugins/Environments.html)
28
+ plugin to configure depending on current `RACK_ENV`.
29
+
30
+ plugin :environments
31
+ plugin :mailer_ext,
32
+ log: (development? or production?),
33
+ prevent_delivery: !production?
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/adam12/roda-mailer_ext.
38
+
39
+ I love pull requests! If you fork this project and modify it, please ping me to see
40
+ if your changes can be incorporated back into this project.
41
+
42
+ That said, if your feature idea is nontrivial, you should probably open an issue to
43
+ [discuss it](http://www.igvita.com/2011/12/19/dont-push-your-pull-requests/)
44
+ before attempting a pull request.
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require "rake/testtask"
2
+ require "rdoc/task"
3
+ require "rubygems/tasks"
4
+
5
+ RDoc::Task.new do |rdoc|
6
+ rdoc.main = "README.md"
7
+ rdoc.rdoc_files.include("README.md", "lib/**/*.rb")
8
+ end
9
+
10
+ Rake::TestTask.new do |t|
11
+ t.libs << "test"
12
+ t.test_files = FileList["test/test*.rb"]
13
+ t.verbose = true
14
+ end
15
+
16
+ Gem::Tasks.new
17
+
18
+ task default: :test
@@ -0,0 +1,66 @@
1
+ # frozen-string-literal: true
2
+
3
+ require "roda"
4
+
5
+ module Roda::RodaPlugins # :nodoc:
6
+ # The mailer_ext plugin extends the mailer plugin with enhanced logging and
7
+ # configuration options.
8
+ #
9
+ # plugin :mailer_ext, log: (ENV["RACK_ENV"] != "test"),
10
+ # prevent_delivery: (ENV["RACK_ENV"] != "production")
11
+ #
12
+ # = Plugin Options
13
+ #
14
+ # The following plugin options are supported:
15
+ #
16
+ # :log :: Output the body of the email to STDOUT before delivery
17
+ # :prevent_delivery :: Uses the +Mail+ test mailer instead of actually
18
+ # attempting the delivery to a SMTP server.
19
+ #
20
+ # = Testing
21
+ #
22
+ # With +:prevent_delivery+ set to true, any outgoing emails are stored inside
23
+ # the +Mail+ test mailer. You can access these during your tests.
24
+ #
25
+ # refute_empty Mail::TestMailer.deliveries
26
+ module MailerExt
27
+ module ResponseMethods # :nodoc:
28
+ def finish
29
+ value = super
30
+
31
+ _log_mail(value) if _should_log_mail(value)
32
+
33
+ value
34
+ end
35
+
36
+ def _log_mail(message)
37
+ puts <<~EOM
38
+
39
+ ==> Sending email to #{message.to.join(", ")}
40
+ #{message}
41
+
42
+ EOM
43
+ end
44
+
45
+ def _should_log_mail(value)
46
+ value.is_a?(Mail::Message) && roda_class.opts[:mailer_ext][:log]
47
+ end
48
+ end
49
+
50
+ def self.load_dependencies(app, opts = {}) # :nodoc:
51
+ app.plugin :mailer
52
+ end
53
+
54
+ def self.configure(app, opts = {}) # :nodoc:
55
+ app.opts[:mailer_ext] = { log: false, prevent_delivery: false }.merge(opts).freeze
56
+
57
+ if app.opts[:mailer_ext][:prevent_delivery]
58
+ Mail.defaults do
59
+ delivery_method :test
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ register_plugin :mailer_ext, MailerExt
66
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roda-mailer_ext
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Daniels
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: roda
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: tilt
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mail
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubygems-tasks
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.2'
97
+ description: |2
98
+ This plugin adds some extensions to the Roda mailer plugin, specifically the ability
99
+ to log outgoing emails, or to prevent actual delivery.
100
+ email: adam@mediadrive.ca
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - README.md
106
+ - Rakefile
107
+ - lib/roda/plugins/mailer_ext.rb
108
+ homepage: https://github.com/adam12/roda-mailer_ext
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.6.8
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: A few helpful extensions to the Roda mailer plugin
132
+ test_files: []