mailtime 0.6.0 → 0.7.0

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: 4164639a2246ede181bb3431c3e79d8762d65a26
4
- data.tar.gz: 3fc802e69ac88adeeaeb4e47e00a3b090405ee92
3
+ metadata.gz: 002fb9cd610aa3981cf339df70530af08af43225
4
+ data.tar.gz: 63b2c8ba97369f4332dcf7304a44ec17176ab157
5
5
  SHA512:
6
- metadata.gz: 4338930085c6a3f4ba5fab74fd05f2d74d06c8a8e0faa73eda55fc241de424282a4696b70c887e093941e66cb5814fd6f8d0730272ec87386ea886e48fea7a35
7
- data.tar.gz: 23df378aabf1e7f46023aede7697df32534211ab022b400ef1fccad15a62909c82add99afe9f9147380c2d02bbcc4eeb47eb1028ea55b80479141e66d626f08d
6
+ metadata.gz: ec3cc6edb99157a6f6b0a91f510e65277b40b58b8a9c1d68136d1363f7f9fbd575ea6b41dcf524f41c214bc3bccd4e2daa2ed3185b2aa8e44daf79dfc754fa9e
7
+ data.tar.gz: d06eef854c7a18f7cf11195deab491d569f523f997b8fc5a69ce4fb602eb0db2280d04b9504e662d91f218ed908258b675772714f32d5c8013465223f2492d2f
@@ -17,28 +17,43 @@ module Mailtime
17
17
 
18
18
  private
19
19
 
20
+ # inject some stuff.
21
+ # to avoid a mostly useless service object, add the mailtime_template and mailtime_layout
20
22
  def inject_metadata
21
23
  mailer_klass = self.class.to_s
22
24
  mailer_action = self.action_name
23
25
  action_variables = self.instance_variables_map
24
26
 
25
27
  self.message.instance_variable_set(:@mailer_klass, mailer_klass)
26
- self.message.instance_variable_set(:@mailer_action, mailer_action)
27
- self.message.instance_variable_set(:@action_variables, action_variables)
28
- self.message.instance_variable_set(:@template_path, self.headers[:template_path] || mailer_klass)
29
- self.message.instance_variable_set(:@template_name, self.headers[:template_name] || mailer_action)
30
- self.message.instance_variable_set(:@mailtime_template, nil)
31
- self.message.instance_variable_set(:@mailtime_layout, nil)
32
-
33
28
  self.message.class.send(:attr_reader, :mailer_klass)
29
+
30
+ self.message.instance_variable_set(:@mailer_action, mailer_action)
34
31
  self.message.class.send(:attr_reader, :mailer_action)
32
+
33
+ self.message.instance_variable_set(:@action_variables, action_variables)
35
34
  self.message.class.send(:attr_reader, :action_variables)
35
+
36
+ self.message.instance_variable_set(:@template_path, self.headers[:template_path] || mailer_klass)
36
37
  self.message.class.send(:attr_reader, :template_path)
38
+
39
+ self.message.instance_variable_set(:@template_name, self.headers[:template_name] || mailer_action)
37
40
  self.message.class.send(:attr_reader, :template_name)
41
+
42
+ self.message.instance_variable_set(:@mailtime_template, find_mailtime_template)
38
43
  self.message.class.send(:attr_accessor, :mailtime_template)
44
+
45
+ self.message.instance_variable_set(:@mailtime_layout, find_mailtime_template.mailtime_mail_layout)
39
46
  self.message.class.send(:attr_accessor, :mailtime_layout)
40
47
  end
41
48
 
49
+ def find_mailtime_template
50
+ _template = Mailtime::MailTemplate.find_by(:klass => self.class.to_s, :action => self.action_name)
51
+ if _template.nil?
52
+ _template = Mailtime::NullTemplate.new(self)
53
+ end
54
+ _template
55
+ end
56
+
42
57
  end
43
58
  end
44
59
  end
@@ -9,7 +9,7 @@ module Mailtime
9
9
  self.table_name = 'mailtime_mail_layouts'
10
10
  has_many :mail_templates, :class_name => 'Mailtime::MailTemplate'
11
11
 
12
- validates_inclusion_of :format, :in => -> { Mailtime.configuration.valid_formats }
12
+ validates_presence_of :format, :in => -> { Mailtime.configuration.valid_formats }
13
13
 
14
14
  end
15
15
 
@@ -8,9 +8,9 @@ module Mailtime
8
8
  included do
9
9
  self.table_name = 'mailtime_mail_templates'
10
10
 
11
- belongs_to :mail_layout, :class_name => 'Mailtime::MailLayout'
12
- validates_inclusion_of :klass, :in => -> { mailers }
13
- validates_inclusion_of :format, :in => -> { Mailtime.configuration.valid_formats }
11
+ belongs_to :mail_layout, :class_name => 'Mailtime::MailLayout', :foreign_key => :mailtime_mail_layout_id
12
+ validates_presence_of :klass, :in => -> { mailers }
13
+ validates_presence_of :format, :in => -> { Mailtime.configuration.valid_formats }
14
14
  validates_uniqueness_of :action, :scope => [:klass, :format]
15
15
 
16
16
  def self.mailers
@@ -22,9 +22,8 @@ module Mailtime
22
22
  end
23
23
  end
24
24
 
25
- def mail_layout
26
- return NullLayout.new unless self[:mail_layout].present?
27
- self[:mail_layout]
25
+ def mailtime_mail_layout
26
+ self.mail_layout.present? ? self.mail_layout : NullLayout.new
28
27
  end
29
28
 
30
29
  def additional_headers
@@ -42,7 +42,7 @@ module Mailtime
42
42
  @fields.each do |field|
43
43
  ::Mailtime::MailLog.create(
44
44
  :loggable => @loggable,
45
- :mailtime_mail_template_id => @template.try(:id),
45
+ :mailtime_mail_template_id => @mail.mailtime_template.try(:id),
46
46
  :action => @mail.mailer_action,
47
47
  :klass => @mail.mailer_klass,
48
48
  :headers => extract_headers,
@@ -19,8 +19,8 @@ module Mailtime
19
19
  protected
20
20
 
21
21
  def process_mail
22
- log_mail
23
22
  render_mail
23
+ log_mail
24
24
  @mail
25
25
  end
26
26
 
@@ -4,8 +4,8 @@ module Mailtime
4
4
 
5
5
  def initialize(mail)
6
6
  @mail = mail
7
- @template = find_template
8
- @layout = find_layout
7
+ @template = @mail.mailtime_template
8
+ @layout = @mail.mailtime_layout
9
9
  end
10
10
 
11
11
  def render
@@ -29,7 +29,7 @@ module Mailtime
29
29
  end
30
30
 
31
31
  def find_layout
32
- @template.mail_layout
32
+ @template.mailtime_mail_layout
33
33
  end
34
34
 
35
35
  def render_and_merge
@@ -3,8 +3,9 @@
3
3
  module Mailtime
4
4
  class NullLayout
5
5
 
6
- attr_reader :content
6
+ attr_reader :content, :id
7
7
  def initialize
8
+ @id = nil
8
9
  @content = "#{Mailtime.configuration.yield_keyword}"
9
10
  end
10
11
 
@@ -24,8 +25,9 @@ module Mailtime
24
25
 
25
26
  class NullTemplate
26
27
 
27
- attr_reader :content
28
+ attr_reader :content, :id
28
29
  def initialize(mail)
30
+ @id = nil
29
31
  @content = mail.body.raw_source
30
32
  end
31
33
 
@@ -1,3 +1,3 @@
1
1
  module Mailtime
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailtime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Brody