Module: BlabberMouth
- Defined in:
- lib/blabber_mouth/blabber_mouth.rb,
lib/blabber_mouth/errors.rb,
lib/blabber_mouth/attachment.rb,
lib/blabber_mouth/validations.rb,
lib/blabber_mouth/adapters/base.rb,
lib/blabber_mouth/adapters/tmail.rb,
lib/blabber_mouth/adapters/xmpp_msg.rb,
lib/blabber_mouth/utils/registry_list.rb,
lib/blabber_mouth/delivery_handlers/smtp.rb,
lib/blabber_mouth/delivery_handlers/test.rb,
lib/blabber_mouth/delivery_handlers/sendmail.rb,
lib/blabber_mouth/delivery_handlers/xmpp_transport.rb
Overview
The heart and soul of the mack-notifier package.
Defined Under Namespace
Modules: Adapters, DeliveryHandlers, Errors, Utils, Validatable Classes: Attachment, Template
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 BlabberMouth object and prepare it for delivery.
-
#attach(file) ⇒ Object
Adds a BlabberMouth::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 BlabberMouth::DeliveryHandlers class.
-
#deliver!(handler = deliver_with) ⇒ Object
Delivers the email with the configured BlabberMouth::DeliveryHandlers class.
-
#deliver_with ⇒ Object
This method returns the delivery handler that will delivers the BlabberMouth 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.
6 7 8 |
# File 'lib/blabber_mouth/blabber_mouth.rb', line 6 def bcc @bcc end |
#cc ⇒ Object
Returns the value of attribute cc.
5 6 7 |
# File 'lib/blabber_mouth/blabber_mouth.rb', line 5 def cc @cc end |
#content_type ⇒ Object
This will attempt to determine the content type of the notification, unless one is already specified.
60 61 62 |
# File 'lib/blabber_mouth/blabber_mouth.rb', line 60 def content_type @content_type end |
#date_sent ⇒ Object
Returns the date sent, defaults to Time.now
74 75 76 |
# File 'lib/blabber_mouth/blabber_mouth.rb', line 74 def date_sent @date_sent end |
#from ⇒ Object
Returns the value of attribute from.
7 8 9 |
# File 'lib/blabber_mouth/blabber_mouth.rb', line 7 def from @from end |
#mime_version ⇒ Object
Returns the mime_version of the notification, defaults to "1.0"
55 56 57 |
# File 'lib/blabber_mouth/blabber_mouth.rb', line 55 def mime_version @mime_version end |
#reply_to ⇒ Object
Returns the reply to address, defaults to the from address.
79 80 81 |
# File 'lib/blabber_mouth/blabber_mouth.rb', line 79 def reply_to @reply_to end |
#subject ⇒ Object
Returns the value of attribute subject.
9 10 11 |
# File 'lib/blabber_mouth/blabber_mouth.rb', line 9 def subject @subject end |
#to ⇒ Object
Returns the value of attribute to.
4 5 6 |
# File 'lib/blabber_mouth/blabber_mouth.rb', line 4 def to @to end |
Instance Method Details
#adapter ⇒ Object
This method returns the adapter that will transform the BlabberMouth object and prepare it for delivery. This method returns the configatron.notifier.adapter parameter. Override this in your BlabberMouth class to specify a different adapter or change the configatron parameter to globally affect all your Notifiers.
Default: :tmail
134 135 136 |
# File 'lib/blabber_mouth/blabber_mouth.rb', line 134 def adapter configatron.blabber_mouth.adapter end |
#attach(file) ⇒ Object
Adds a BlabberMouth::Attachment to the notifier. Raise ArgumentError if the parameter is not a BlabberMouth::Attachment
85 86 87 88 |
# File 'lib/blabber_mouth/blabber_mouth.rb', line 85 def attach(file) raise ArgumentError.new unless file.is_a?(BlabberMouth::Attachment) << file end |
#attachments ⇒ Object
Returns the attachments Array.
96 97 98 |
# File 'lib/blabber_mouth/blabber_mouth.rb', line 96 def ||= [] 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.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/blabber_mouth/blabber_mouth.rb', line 39 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.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/blabber_mouth/blabber_mouth.rb', line 16 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 BlabberMouth::DeliveryHandlers class. Returns false if there are any errors.
102 103 104 105 106 107 108 109 |
# File 'lib/blabber_mouth/blabber_mouth.rb', line 102 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 BlabberMouth::DeliveryHandlers class.
112 113 114 |
# File 'lib/blabber_mouth/blabber_mouth.rb', line 112 def deliver!(handler = deliver_with) "BlabberMouth::DeliveryHandlers::#{handler.to_s.camelcase}".constantize.deliver(self) end |
#deliver_with ⇒ Object
This method returns the delivery handler that will delivers the BlabberMouth object. This method returns the configatron.blabber_mouth.deliver_with parameter. Override this in your BlabberMouth class to specify a different handler or change the configatron parameter to globally affect all your Notifiers.
Default: :sendmail
144 145 146 |
# File 'lib/blabber_mouth/blabber_mouth.rb', line 144 def deliver_with configatron.blabber_mouth.deliver_with end |
#deliverable(adap = adapter) ⇒ Object
Returns a ready to be delivered, encoded, version of the notification.
122 123 124 125 126 |
# File 'lib/blabber_mouth/blabber_mouth.rb', line 122 def deliverable(adap = adapter) adap = "BlabberMouth::Adapters::#{adap.to_s.camelcase}".constantize.new(self) adap.convert adap.deliverable end |
#has_attachments? ⇒ Boolean
Returns true if there are attachments.
91 92 93 |
# File 'lib/blabber_mouth/blabber_mouth.rb', line 91 def !.empty? end |
#recipients ⇒ Object
Returns all the recipients of this notifier.
117 118 119 |
# File 'lib/blabber_mouth/blabber_mouth.rb', line 117 def recipients [self.to, self.cc, self.bcc].flatten.compact end |