class MailHandler::Receiving::Notification::Email
notification in form of sent email
Constants
- EMAIL_TYPES
Attributes
contacts[RW]
current_state[R]
from[RW]
max_time_to_notify[RW]
min_time_to_notify[RW]
sender[RW]
Public Class Methods
new(sender, from, to, min_time_to_notify = 60)
click to toggle source
# File lib/mailhandler/receiving/notification/email.rb, line 20 def initialize(sender, from, to, min_time_to_notify = 60) @min_time_to_notify = min_time_to_notify @sender = sender @from = from @contacts = to init_state change_content_handler(EmailContent.new) end
Public Instance Methods
change_content_handler(content_handler)
click to toggle source
Allow users to specify their own content classes. Class must match by methods to the interface of MailHandler::Receiving::Notification::EmailContent
# File lib/mailhandler/receiving/notification/email.rb, line 48 def change_content_handler(content_handler) @content_handler = content_handler end
change_state(state)
click to toggle source
# File lib/mailhandler/receiving/notification/email.rb, line 36 def change_state(state) @current_state = state end
notify(search)
click to toggle source
# File lib/mailhandler/receiving/notification/email.rb, line 30 def notify(search) @max_time_to_notify = search.max_duration init_state if Time.now - search.started_at < min_time_to_notify @current_state.notify(search) end
send_email(type, search)
click to toggle source
# File lib/mailhandler/receiving/notification/email.rb, line 40 def send_email(type, search) verify_email_type(type) content = @content_handler.retrieve(type, search.options, Time.now - search.started_at, from, contacts) sender.send_email content end
Private Instance Methods
init_state()
click to toggle source
# File lib/mailhandler/receiving/notification/email.rb, line 54 def init_state @current_state = Notification::NoDelay.new(self) end
verify_email_type(type)
click to toggle source
# File lib/mailhandler/receiving/notification/email.rb, line 60 def verify_email_type(type) return if EMAIL_TYPES.include?(type) raise MailHandler::TypeError, "Incorrect type: #{type}, allowed types: #{EMAIL_TYPES}." end