Class: Forklift::Base::Mailer
- Inherits:
-
Object
- Object
- Forklift::Base::Mailer
- Defined in:
- lib/forklift/base/mailer.rb
Defined Under Namespace
Classes: ERBBinding
Instance Method Summary collapse
-
#config ⇒ Object
Public: Pull out the settings from config/email.yml.
- #forklift ⇒ Object
-
#initialize(forklift) ⇒ Mailer
constructor
A new instance of Mailer.
- #message_defaults ⇒ Object
- #send(args, attachment_lines = []) ⇒ Object
- #send_template(args, template_file, variables, attachment_lines = []) ⇒ Object
Constructor Details
#initialize(forklift) ⇒ Mailer
Returns a new instance of Mailer.
9 10 11 |
# File 'lib/forklift/base/mailer.rb', line 9 def initialize(forklift) @forklift = forklift end |
Instance Method Details
#config ⇒ Object
Public: Pull out the settings from config/email.yml.
Returns a Hash with all symbolized keys.
16 17 18 19 |
# File 'lib/forklift/base/mailer.rb', line 16 def config config_file = "#{forklift.config[:project_root]}/config/email.yml" @config ||= forklift.utils.load_yml(config_file).deep_symbolize_keys end |
#forklift ⇒ Object
21 22 23 |
# File 'lib/forklift/base/mailer.rb', line 21 def forklift @forklift end |
#message_defaults ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/forklift/base/mailer.rb', line 25 def { from: "Forklift", subject: "Forklift has moved your database @ #{Time.new}", body: "Forklift has moved your database @ #{Time.new}", } end |
#send(args, attachment_lines = []) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/forklift/base/mailer.rb', line 41 def send(args, =[]) params = [:to, :from, :subject, :body].each do |i| params[i] = args[i] unless args[i].nil? end if .length > 0 params[:attachments] = {"log.txt" => .join("\r\n")} end deliver(params) end |
#send_template(args, template_file, variables, attachment_lines = []) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/forklift/base/mailer.rb', line 33 def send_template(args, template_file, variables, =[]) renderer = ERB.new(File.read(template_file)) binder = ERBBinding.new(variables) body = renderer.result(binder.get_binding) args[:body] = body send(args, ) end |