Module: Mack::Notifier
- Defined in:
- lib/mack-notifier/notifier.rb,
lib/mack-notifier/attachment.rb,
lib/mack-notifier/validations.rb,
lib/mack-notifier/adapters/base.rb,
lib/mack-notifier/adapters/tmail.rb,
lib/mack-notifier/adapters/xmpp_msg.rb,
lib/mack-notifier/delivery_handlers/smtp.rb,
lib/mack-notifier/delivery_handlers/test.rb,
lib/mack-notifier/delivery_handlers/sendmail.rb,
lib/mack-notifier/delivery_handlers/xmpp_transport.rb
Overview
The heart and soul of the mack-notifier package.
Defined Under Namespace
Modules: Adapters, DeliveryHandlers, Validatable Classes: Attachment
Instance Attribute Summary collapse
-
#bcc ⇒ Object
Returns the value of attribute bcc.
-
#cc ⇒ Object
Returns the value of attribute cc.
-
#content_type ⇒ Object
This will attempt to determine the content type of the notification, unless one is already specified.
-
#date_sent ⇒ Object
Returns the date sent, defaults to Time.now.
-
#from ⇒ Object
Returns the value of attribute from.
-
#mime_version ⇒ Object
Returns the mime_version of the notification, defaults to “1.0”.
-
#reply_to ⇒ Object
Returns the reply to address, defaults to the from address.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
-
#adapter ⇒ Object
This method returns the adapter that will transform the Mack::Notifier object and prepare it for delivery.
-
#attach(file) ⇒ Object
Adds a Mack::Notifier::Attachment to the notifier.
-
#attachments ⇒ Object
Returns the attachments Array.
-
#body(part, value = nil) ⇒ Object
If called with two parameters it will set the value of the body type to the second parameter.
-
#build(options = {}) ⇒ Object
A helper method that takes a Hash and will populate the notification with the key/value pairs of that Hash.
-
#deliver(handler = deliver_with) ⇒ Object
Delivers the notification with the configured Mack::Notifier::DeliveryHandlers class.
-
#deliver!(handler = deliver_with) ⇒ Object
Delivers the email with the configured Mack::Notifier::DeliveryHandlers class.
-
#deliver_with ⇒ Object
This method returns the delivery handler that will delivers the Mack::Notifier object.
-
#deliverable(adap = adapter) ⇒ Object
Returns a ready to be delivered, encoded, version of the notification.
-
#has_attachments? ⇒ Boolean
Returns true if there are attachments.
-
#recipients ⇒ Object
Returns all the recipients of this notifier.
Instance Attribute Details
#bcc ⇒ Object
Returns the value of attribute bcc.
7 8 9 |
# File 'lib/mack-notifier/notifier.rb', line 7 def bcc @bcc end |
#cc ⇒ Object
Returns the value of attribute cc.
6 7 8 |
# File 'lib/mack-notifier/notifier.rb', line 6 def cc @cc end |
#content_type ⇒ Object
This will attempt to determine the content type of the notification, unless one is already specified.
61 62 63 |
# File 'lib/mack-notifier/notifier.rb', line 61 def content_type @content_type end |
#date_sent ⇒ Object
Returns the date sent, defaults to Time.now
75 76 77 |
# File 'lib/mack-notifier/notifier.rb', line 75 def date_sent @date_sent end |
#from ⇒ Object
Returns the value of attribute from.
8 9 10 |
# File 'lib/mack-notifier/notifier.rb', line 8 def from @from end |
#mime_version ⇒ Object
Returns the mime_version of the notification, defaults to “1.0”
56 57 58 |
# File 'lib/mack-notifier/notifier.rb', line 56 def mime_version @mime_version end |
#reply_to ⇒ Object
Returns the reply to address, defaults to the from address.
80 81 82 |
# File 'lib/mack-notifier/notifier.rb', line 80 def reply_to @reply_to end |
#subject ⇒ Object
Returns the value of attribute subject.
10 11 12 |
# File 'lib/mack-notifier/notifier.rb', line 10 def subject @subject end |
#to ⇒ Object
Returns the value of attribute to.
5 6 7 |
# File 'lib/mack-notifier/notifier.rb', line 5 def to @to end |
Instance Method Details
#adapter ⇒ Object
This method returns the adapter that will transform the Mack::Notifier object and prepare it for delivery. This method returns the configatron.notifier.adapter parameter. Override this in your Mack::Notifier class to specify a different adapter or change the configatron parameter to globally affect all your Notifiers.
Default: :tmail
135 136 137 |
# File 'lib/mack-notifier/notifier.rb', line 135 def adapter configatron.mack.notifier.adapter end |
#attach(file) ⇒ Object
Adds a Mack::Notifier::Attachment to the notifier. Raise ArgumentError if the parameter is not a Mack::Notifier::Attachment
86 87 88 89 |
# File 'lib/mack-notifier/notifier.rb', line 86 def attach(file) raise ArgumentError.new unless file.is_a?(Mack::Notifier::Attachment) << file end |
#attachments ⇒ Object
Returns the attachments Array.
97 98 99 |
# File 'lib/mack-notifier/notifier.rb', line 97 def @attachments ||= [] end |
#body(part, value = nil) ⇒ Object
If called with two parameters it will set the value of the body type to the second parameter.
Example:
body(:plain, "hello") # => sets the 'plain' body to "hello"
If called with just one parameter it will return the value of that body type. If the value is nil the template for that body type will be rendered.
Example:
body(:plain) # => "hello"
body(:html) # => will call the html.erb template for this notifier.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mack-notifier/notifier.rb', line 40 def body(part, value = nil) part = part.to_sym if value.nil? body = bodies[part] if body.blank? bodies[part] = build_template(part) return bodies[part] else return body end else bodies[part] = value end end |
#build(options = {}) ⇒ Object
A helper method that takes a Hash and will populate the notification with the key/value pairs of that Hash. Use body_* to set a body part.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mack-notifier/notifier.rb', line 17 def build( = {}) .each do |k,v| k = k.to_s unless k.match(/^body_/) self.send("#{k}=", v) else k.gsub!("body_", "") self.body(k, v) end end end |
#deliver(handler = deliver_with) ⇒ Object
Delivers the notification with the configured Mack::Notifier::DeliveryHandlers class. Returns false if there are any errors.
103 104 105 106 107 108 109 110 |
# File 'lib/mack-notifier/notifier.rb', line 103 def deliver(handler = deliver_with) begin deliver!(handler) rescue Exception => e return false end return true end |
#deliver!(handler = deliver_with) ⇒ Object
Delivers the email with the configured Mack::Notifier::DeliveryHandlers class.
113 114 115 |
# File 'lib/mack-notifier/notifier.rb', line 113 def deliver!(handler = deliver_with) "Mack::Notifier::DeliveryHandlers::#{handler.to_s.camelcase}".constantize.deliver(self) end |
#deliver_with ⇒ Object
This method returns the delivery handler that will delivers the Mack::Notifier object. This method returns the configatron.mack.notifier.deliver_with parameter. Override this in your Mack::Notifier class to specify a different handler or change the configatron parameter to globally affect all your Notifiers.
Default: :sendmail
145 146 147 |
# File 'lib/mack-notifier/notifier.rb', line 145 def deliver_with configatron.mack.notifier.deliver_with end |
#deliverable(adap = adapter) ⇒ Object
Returns a ready to be delivered, encoded, version of the notification.
123 124 125 126 127 |
# File 'lib/mack-notifier/notifier.rb', line 123 def deliverable(adap = adapter) adap = "Mack::Notifier::Adapters::#{adap.to_s.camelcase}".constantize.new(self) adap.convert adap.deliverable end |
#has_attachments? ⇒ Boolean
Returns true if there are attachments.
92 93 94 |
# File 'lib/mack-notifier/notifier.rb', line 92 def !.empty? end |
#recipients ⇒ Object
Returns all the recipients of this notifier.
118 119 120 |
# File 'lib/mack-notifier/notifier.rb', line 118 def recipients [self.to, self.cc, self.bcc].flatten.compact end |