Class: Mailtime::MailLogService
- Inherits:
-
Object
- Object
- Mailtime::MailLogService
- Defined in:
- lib/mailtime/processor/mail_log_service.rb
Instance Attribute Summary collapse
-
#field ⇒ Object
Returns the value of attribute field.
-
#loggable ⇒ Object
Returns the value of attribute loggable.
Instance Method Summary collapse
- #attribute_is_loggable?(var) ⇒ Boolean
- #class_is_loggable?(var) ⇒ Boolean
- #create_mail_log ⇒ Object
- #execute ⇒ Object
- #extract_headers ⇒ Object
- #extract_scope ⇒ Object
-
#initialize(mail, loggable_class, options) ⇒ MailLogService
constructor
A new instance of MailLogService.
- #log ⇒ Object
- #loggable? ⇒ Boolean
Constructor Details
#initialize(mail, loggable_class, options) ⇒ MailLogService
Returns a new instance of MailLogService.
5 6 7 8 9 10 11 |
# File 'lib/mailtime/processor/mail_log_service.rb', line 5 def initialize(mail, loggable_class, ) @mail = mail @loggable_class = loggable_class @loggable = nil @options = @fields = [] end |
Instance Attribute Details
#field ⇒ Object
Returns the value of attribute field.
4 5 6 |
# File 'lib/mailtime/processor/mail_log_service.rb', line 4 def field @field end |
#loggable ⇒ Object
Returns the value of attribute loggable.
4 5 6 |
# File 'lib/mailtime/processor/mail_log_service.rb', line 4 def loggable @loggable end |
Instance Method Details
#attribute_is_loggable?(var) ⇒ Boolean
32 33 34 35 36 37 38 39 |
# File 'lib/mailtime/processor/mail_log_service.rb', line 32 def attribute_is_loggable?(var) fields = @options[:fields] || Mailtime.configuration.log_fields || [:to, :cc, :bcc] fields.each do |field| if @mail.send(field).include?(var.send(@options[:attribute])) @fields << field end end end |
#class_is_loggable?(var) ⇒ Boolean
26 27 28 29 30 |
# File 'lib/mailtime/processor/mail_log_service.rb', line 26 def class_is_loggable?(var) if var.class.to_s == @loggable_class @loggable = var end end |
#create_mail_log ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mailtime/processor/mail_log_service.rb', line 41 def create_mail_log @fields.each do |field| ::Mailtime::MailLog.create( :loggable => @loggable, :mailtime_mail_template_id => @template.try(:id), :action => @mail.mailer_action, :klass => @mail.mailer_klass, :headers => extract_headers, :scope => extract_scope, :field => field ) end end |
#execute ⇒ Object
13 14 15 |
# File 'lib/mailtime/processor/mail_log_service.rb', line 13 def execute log end |
#extract_headers ⇒ Object
55 56 57 58 59 |
# File 'lib/mailtime/processor/mail_log_service.rb', line 55 def extract_headers headers = {} @mail.header_fields.map { |k| headers[k.name] = k.value } headers end |
#extract_scope ⇒ Object
61 62 63 |
# File 'lib/mailtime/processor/mail_log_service.rb', line 61 def extract_scope @mail.action_variables.as_json.except(*Mailtime.configuration.reject_scope_keys) end |
#log ⇒ Object
17 18 19 20 |
# File 'lib/mailtime/processor/mail_log_service.rb', line 17 def log return unless loggable? create_mail_log end |
#loggable? ⇒ Boolean
22 23 24 |
# File 'lib/mailtime/processor/mail_log_service.rb', line 22 def loggable? @mail.action_variables.detect { |_, var| class_is_loggable?(var) && attribute_is_loggable?(var) } && @fields.any? end |