Class: Lux::Mailer
- Includes:
- ClassCallbacks
- Defined in:
- lib/lux/mailer/mailer.rb
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(:email_login, ‘[email protected]’).
- .render(method_name, *args) ⇒ Object
Instance Method Summary collapse
- #body ⇒ Object
- #deliver ⇒ Object
-
#initialize ⇒ Mailer
constructor
A new instance of Mailer.
- #subject ⇒ Object
- #to ⇒ Object
Constructor Details
#initialize ⇒ Mailer
Returns a new instance of Mailer.
59 60 61 |
# File 'lib/lux/mailer/mailer.rb', line 59 def initialize @mail = {}.to_hwia :subject, :body, :to, :cc, :from end |
Instance Attribute Details
#mail ⇒ Object (readonly)
Returns the value of attribute mail.
25 26 27 |
# File 'lib/lux/mailer/mailer.rb', line 25 def mail @mail end |
Class Method Details
.deliver ⇒ Object
52 53 54 |
# File 'lib/lux/mailer/mailer.rb', line 52 def deliver send(method_name, *args).deliver end |
.method_missing(method_sym, *args) ⇒ Object
48 49 50 |
# File 'lib/lux/mailer/mailer.rb', line 48 def method_missing method_sym, *args prepare(method_sym, *args) end |
.prepare(template, *args) ⇒ Object
Mailer.prepare(:email_login, ‘[email protected]’)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/lux/mailer/mailer.rb', line 29 def prepare template, *args obj = new obj.instance_variable_set :@_template, template obj.run_callback :before if args[0].class == Hash obj.send template, **args[0] else obj.send template, *args end obj.run_callback :after obj end |
.render(method_name, *args) ⇒ Object
44 45 46 |
# File 'lib/lux/mailer/mailer.rb', line 44 def render method_name, *args send(method_name, *args).body end |
Instance Method Details
#body ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/lux/mailer/mailer.rb', line 63 def body data = @mail.body unless data helper = Lux::Template::Helper.new self, self.class.helper layout = Lux::Template.find_layout './app/views', self.class.layout data = Lux::Template.render helper, template: "#{cattr.template_root}/mailer/#{@_template}", layout: layout end data.gsub(%r{\shref=(['"])/}) { %[ href=#{$1}#{Lux.config.host}/] } end |
#deliver ⇒ Object
83 84 85 86 87 |
# File 'lib/lux/mailer/mailer.rb', line 83 def deliver if m = build_mail_object Lux.current.delay(m) { |mail| mail.deliver! } end end |
#subject ⇒ Object
75 76 77 |
# File 'lib/lux/mailer/mailer.rb', line 75 def subject @mail.subject end |
#to ⇒ Object
79 80 81 |
# File 'lib/lux/mailer/mailer.rb', line 79 def to @mail.to end |