Class: Lux::Mailer
Overview
Rails mode via method missing is suported Mailer.confirm_email(‘rejotl@gmailcom’).deliver Mailer.confirm_email(‘rejotl@gmailcom’).body
Instance Attribute Summary collapse
-
#mail ⇒ Object
readonly
Returns the value of attribute mail.
Class Method Summary collapse
- .deliver ⇒ Object
- .method_missing(method_sym, *args) ⇒ Object
-
.prepare(template, *args) ⇒ Object
Mailer.prepare(:confirm_email, ‘rejotl@gmailcom’).
- .render(method_name, *args) ⇒ Object
Instance Method Summary collapse
- #body ⇒ Object
- #deliver ⇒ Object
- #deliver_later ⇒ Object
-
#initialize ⇒ Mailer
constructor
A new instance of Mailer.
- #subject ⇒ Object
- #to ⇒ Object
Constructor Details
#initialize ⇒ Mailer
Returns a new instance of Mailer.
47 48 49 |
# File 'lib/lux/mailer/mailer.rb', line 47 def initialize @mail = DynamicClass.new subject: nil, body: nil, to: nil, cc: nil, from: nil end |
Instance Attribute Details
#mail ⇒ Object (readonly)
Returns the value of attribute mail.
17 18 19 |
# File 'lib/lux/mailer/mailer.rb', line 17 def mail @mail end |
Class Method Details
.deliver ⇒ Object
40 41 42 |
# File 'lib/lux/mailer/mailer.rb', line 40 def deliver send(method_name, *args).deliver end |
.method_missing(method_sym, *args) ⇒ Object
36 37 38 |
# File 'lib/lux/mailer/mailer.rb', line 36 def method_missing method_sym, *args prepare(method_sym, *args) end |
.prepare(template, *args) ⇒ Object
Mailer.prepare(:confirm_email, ‘rejotl@gmailcom’)
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lux/mailer/mailer.rb', line 21 def prepare template, *args obj = new obj.instance_variable_set :@_template, template ClassCallbacks.execute obj, :before obj.send template, *args ClassCallbacks.execute obj, :after obj end |
.render(method_name, *args) ⇒ Object
32 33 34 |
# File 'lib/lux/mailer/mailer.rb', line 32 def render method_name, *args send(method_name, *args).body end |
Instance Method Details
#body ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/lux/mailer/mailer.rb', line 74 def body return @mail.body if @mail.body helper = Lux::Helper.new self, self.class.helper Lux::Template.render_with_layout "mailer/#{@_template}", helper end |
#deliver ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/lux/mailer/mailer.rb', line 51 def deliver raise "From in mailer not defined" unless @mail.from raise "To in mailer not defined" unless @mail.to raise "Subject in mailer not defined" unless @mail.subject require 'mail' Mail.defaults { delivery_method Lux.config(:mail).delivery, Lux.config(:mail).opts } m = Mail.new m[:from] = @mail.from m[:to] = @mail.to m[:subject] = @mail.subject m[:body] = @mail.body || body m[:content_type] = 'text/html; charset=UTF-8' Thread.new { m.deliver! } end |
#deliver_later ⇒ Object
70 71 72 |
# File 'lib/lux/mailer/mailer.rb', line 70 def deliver_later Lux.delay self, :deliver end |
#subject ⇒ Object
82 83 84 |
# File 'lib/lux/mailer/mailer.rb', line 82 def subject @mail.subject end |
#to ⇒ Object
86 87 88 |
# File 'lib/lux/mailer/mailer.rb', line 86 def to @mail.to end |