Sha256: 6d58da74e9125c7bb654a03d2329d93b5a2d1282d62b3405c57664bb031d357b
Contents?: true
Size: 1.86 KB
Versions: 9
Compression:
Stored size: 1.86 KB
Contents
class MailEngine::MailDispatcher < ActionMailer::Base default :from => "info@itjob.fm" sendgrid_header do category MailEngine::Base.current_config["sendgrid_category"] filters { opentrack "enable" => 1 clicktrack "enable" => 1 subscriptiontrack "enable" => 0 template "enable" => 0 footer "enable" => 0 } end protected ### # MailEngine::MailDispatcher.{any template name}( # :subject => 'hello', # :to => 'm@theplant.jp', # :values => {:username => @user.name} # ).deliver # def self.method_missing(method, *args) return super if respond_to?(method) # basically it won't unless subclass options = args.dup.extract_options! options[:locale] ||= I18n.locale # TODO if template file exists, don't need to exam the db. templates = MailEngine::MailTemplate.where(:path => method, :locale => options[:locale], :for_marketing => true, :partial => false).order('format desc').all raise "No Template added." if templates.blank? subject = templates.first.subject formats = templates.map {|t| "format.#{t.format}" }.sort.reverse # generate the method for db template. class_eval <<-METHOD def #{method} options ### extract mail options, used for mail method. mail_options = {} mail_options[:subject] = "#{%Q{#{subject}}}" options.delete_if {|key, value| if [:subject, :to, :from, :cc, :bcc, :reply_to, :date].include?(key.to_sym) mail_options[key] = value true else false end } ### store :values to instance value (options[:values]||[]).each do |key, value| instance_variable_set "@" + key.to_s, value end mail mail_options do |format| #{formats.join(';')} end end METHOD new(method, *args).message end end
Version data entries
9 entries across 9 versions & 1 rubygems