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 = @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
33 34 35 36 37 38 39 40 |
# File 'lib/mailtime/processor/mail_log_service.rb', line 33 def attribute_is_loggable?(var) fields = [:fields] || Mailtime.configuration.log_fields || [:to, :cc, :bcc] fields.each do |field| if @mail.send(field).include?(var.send([:attribute])) @fields << field end end end |
#class_is_loggable?(var) ⇒ Boolean
26 27 28 29 30 31 |
# 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 return false end |
#create_mail_log ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mailtime/processor/mail_log_service.rb', line 42 def create_mail_log @fields.each do |field| ::Mailtime::MailLog.create( :loggable => @loggable, :mailtime_mail_template_id => @mail.mailtime_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
56 57 58 59 60 |
# File 'lib/mailtime/processor/mail_log_service.rb', line 56 def extract_headers headers = {} @mail.header_fields.map { |k| headers[k.name] = k.value } headers end |
#extract_scope ⇒ Object
62 63 64 |
# File 'lib/mailtime/processor/mail_log_service.rb', line 62 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 |