cells-mailer 0.3.0 → 0.4.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile +1 -0
- data/README.md +15 -3
- data/lib/cell/mailer/configuration.rb +45 -0
- data/lib/cell/mailer/version.rb +1 -1
- data/lib/cell/mailer.rb +24 -19
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83f7e7d1776d36365534b7d138b15fa29de2ddeb
|
4
|
+
data.tar.gz: 5c2a36aba0182cf3f70ca97cd914e2e2e0d319aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1295b6794f28f77da5e842e403b20295f910e1f3175b9d90025bc859c4ab5e8a7f50d1faa8cf422285c5fac4e946169b5c10d2efc95856c3ba28970a71a3445b
|
7
|
+
data.tar.gz: 7a16e2ad3076e5d8896b8948e0dd5963da9ed0a8a1a29d418ff4ec99310f89845a0127a3da37c1e55a5a0ae9c9816ada6ea9c18c616982af8174f9aa74b621e8
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v0.4.0 [☰](https://github.com/timoschilling/cells-mailer/compare/v0.3.0...v0.4.0)
|
4
|
+
|
5
|
+
* global configuration
|
6
|
+
* inherited configuration
|
7
|
+
|
3
8
|
## v0.3.0 [☰](https://github.com/timoschilling/cells-mailer/compare/v0.2.0...v0.3.0)
|
4
9
|
|
5
10
|
* class level options
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -16,9 +16,21 @@ And then execute:
|
|
16
16
|
|
17
17
|
## Configuration
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
### Global configuration
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
Cell::Mailer.configure do
|
23
|
+
to "nick@trailblazer.to"
|
24
|
+
from "timo@schilling.io"
|
25
|
+
subject "Nick ruls!"
|
26
|
+
mail_options deliver_method: :smtp
|
27
|
+
end
|
28
|
+
```
|
29
|
+
`mail_options` will be passed to the `Mail` gem, for details take a look on the [Mail](https://github.com/mikel/mail) gem.
|
30
|
+
|
31
|
+
### Context configuration
|
32
|
+
|
33
|
+
See next chapter.
|
22
34
|
|
23
35
|
## Usage
|
24
36
|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Cell
|
2
|
+
module Mailer
|
3
|
+
class Configuration
|
4
|
+
class << self
|
5
|
+
def attributes
|
6
|
+
{ to: nil, from: nil, subject: nil, mail_options: {} }
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
self.attributes.each do |name, value|
|
11
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
12
|
+
def #{name}(value = nil)
|
13
|
+
store[:#{name}] = value if value
|
14
|
+
store[:#{name}]
|
15
|
+
end
|
16
|
+
|
17
|
+
def #{name}=(value)
|
18
|
+
store[:#{name}] = value
|
19
|
+
end
|
20
|
+
RUBY
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(args = {})
|
24
|
+
if (wrong_keys = args.keys - self.class.attributes.keys).any?
|
25
|
+
raise ArgumentError, "`:#{wrong_keys.first}` is not a valid argument!"
|
26
|
+
end
|
27
|
+
|
28
|
+
@store = self.class.attributes.merge(args)
|
29
|
+
end
|
30
|
+
|
31
|
+
def clone
|
32
|
+
cloned_store = {}
|
33
|
+
store.each do |key, value|
|
34
|
+
next if [Symbol, TrueClass, FalseClass, NilClass].include? value.class
|
35
|
+
cloned_store[key] = value.clone
|
36
|
+
end
|
37
|
+
self.class.new cloned_store
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
attr_reader :store
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/cell/mailer/version.rb
CHANGED
data/lib/cell/mailer.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "cells"
|
2
|
+
require "cell/mailer/configuration"
|
2
3
|
require "cell/mailer/version"
|
3
4
|
require "mail"
|
4
5
|
|
@@ -8,6 +9,18 @@ module Cell
|
|
8
9
|
base.extend ClassMethods
|
9
10
|
end
|
10
11
|
|
12
|
+
def self.configure(&block)
|
13
|
+
configuration.instance_eval &block
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.configuration
|
17
|
+
@configuration ||= Cell::Mailer::Configuration.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.clear_configuration!
|
21
|
+
@configuration = nil
|
22
|
+
end
|
23
|
+
|
11
24
|
def deliver(options = {})
|
12
25
|
mail = Mail.new process_mail_options(options)
|
13
26
|
mail.deliver
|
@@ -25,10 +38,10 @@ module Cell
|
|
25
38
|
end
|
26
39
|
|
27
40
|
[:to, :subject, :from].each do |field|
|
28
|
-
options[field] ||= self.class.send(field)
|
41
|
+
options[field] ||= self.class.mailer.send(field)
|
29
42
|
end
|
30
43
|
|
31
|
-
(self.class.mail_options || {}).each do |key, value|
|
44
|
+
(self.class.mailer.mail_options || {}).each do |key, value|
|
32
45
|
options[key] = value
|
33
46
|
end
|
34
47
|
|
@@ -39,27 +52,19 @@ module Cell
|
|
39
52
|
end
|
40
53
|
|
41
54
|
module ClassMethods
|
42
|
-
def
|
43
|
-
|
44
|
-
|
45
|
-
base.inheritable_attr :from
|
46
|
-
base.inheritable_attr :subject
|
47
|
-
base.inheritable_attr :mail_options
|
55
|
+
def mailer(&block)
|
56
|
+
mailer_configuration.instance_eval &block if block
|
57
|
+
mailer_configuration
|
48
58
|
end
|
49
59
|
|
50
|
-
|
51
|
-
|
60
|
+
private
|
61
|
+
|
62
|
+
def mailer_configuration
|
63
|
+
@mailer_configuration ||= Cell::Mailer.configuration.clone
|
52
64
|
end
|
53
65
|
|
54
|
-
def
|
55
|
-
|
56
|
-
instance_eval %Q{
|
57
|
-
def #{name}(value = :__undefined)
|
58
|
-
return self.#{name} = value if value != :__undefined
|
59
|
-
return @#{name} if instance_variable_defined?(:@#{name})
|
60
|
-
@#{name} = Uber::InheritableAttribute.inherit_for(self, :#{name}, #{options})
|
61
|
-
end
|
62
|
-
}
|
66
|
+
def inherited(child)
|
67
|
+
child.instance_variable_set(:@mailer_configuration, mailer_configuration.clone)
|
63
68
|
end
|
64
69
|
end
|
65
70
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cells-mailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timo Schilling
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- bin/setup
|
100
100
|
- cells-mailer.gemspec
|
101
101
|
- lib/cell/mailer.rb
|
102
|
+
- lib/cell/mailer/configuration.rb
|
102
103
|
- lib/cell/mailer/version.rb
|
103
104
|
- lib/cells-mailer.rb
|
104
105
|
homepage: http://github.com/timoschilling/cells-mailer
|