Class: Porteo::Mail_protocol
- Defined in:
- lib/protocols/mail_protocol.rb
Overview
Implementation of email protocol to be used in Porteo system. It only define specific behavior for this protocol.
Constant Summary collapse
- MAIL_REQUIRED_FIELDS =
Necessary fields to send a valid email
[:to, :body]
Instance Attribute Summary
Attributes inherited from Protocol
Instance Method Summary collapse
-
#check_message_sections ⇒ nil
Check for all required field to exist and contain valid values.
-
#override_tags ⇒ nil
Implementates the parent method to ensure that email receptor is the one set at receiver instance variable not the :to template tag.
Methods inherited from Protocol
#initialize, #message, #send_message, #set_template, #set_template_params
Constructor Details
This class inherits a constructor from Porteo::Protocol
Instance Method Details
#check_message_sections ⇒ nil
Check for all required field to exist and contain valid values. If any required field is missing or its syntax is not valid an ArgumentException is raised.
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/protocols/mail_protocol.rb', line 49 def raise ArgumentError, "Protocol Error. There are no template sections. Maybe you didn't load a complete template" unless @message_sections != nil # Check for required fields MAIL_REQUIRED_FIELDS.each do |field| raise ArgumentError, "Protocol Error. #{field.to_s.capitalize} is a required field for this protocol and it was not defined" unless @message_sections[field] != nil end # Check for correct syntax if not @message_sections[:to] =~ /[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}/ raise ArgumentError, "Protocol Error. Bad syntax in :to section" end end |
#override_tags ⇒ nil
Implementates the parent method to ensure that email receptor is the one set at receiver instance variable not the :to template tag
37 38 39 40 41 |
# File 'lib/protocols/mail_protocol.rb', line 37 def # In mail protocol, the receiver instance variable has precedence over # :to tag in template @message_sections[:to] = @receiver unless @receiver == nil end |