Class: Lux::Mailer

Inherits:
Object show all
Includes:
ClassCallbacks
Defined in:
lib/lux/mailer/mailer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMailer

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

#mailObject (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

.deliverObject



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

#bodyObject



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

#deliverObject



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

#subjectObject



75
76
77
# File 'lib/lux/mailer/mailer.rb', line 75

def subject
  @mail.subject
end

#toObject



79
80
81
# File 'lib/lux/mailer/mailer.rb', line 79

def to
  @mail.to
end