The heart and soul of the mack-notifier package.
| bcc | [RW] | |
| cc | [RW] | |
| content_type | [RW] | |
| date_sent | [RW] | |
| from | [RW] | |
| mime_version | [RW] | |
| reply_to | [RW] | |
| subject | [RW] | |
| to | [RW] |
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
# File lib/mack-notifier/notifier.rb, line 135
135: def adapter
136: configatron.mack.notifier.adapter
137: end
Adds a Mack::Notifier::Attachment to the notifier. Raise ArgumentError if the parameter is not a Mack::Notifier::Attachment
# File lib/mack-notifier/notifier.rb, line 86
86: def attach(file)
87: raise ArgumentError.new unless file.is_a?(Mack::Notifier::Attachment)
88: attachments << file
89: end
Returns the attachments Array.
# File lib/mack-notifier/notifier.rb, line 97
97: def attachments
98: @attachments ||= []
99: end
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.
# File lib/mack-notifier/notifier.rb, line 40
40: def body(part, value = nil)
41: part = part.to_sym
42: if value.nil?
43: body = bodies[part]
44: if body.blank?
45: bodies[part] = build_template(part)
46: return bodies[part]
47: else
48: return body
49: end
50: else
51: bodies[part] = value
52: end
53: end
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.
# File lib/mack-notifier/notifier.rb, line 17
17: def build(options = {})
18: options.each do |k,v|
19: k = k.to_s
20: unless k.match(/^body_/)
21: self.send("#{k}=", v)
22: else
23: k.gsub!("body_", "")
24: self.body(k, v)
25: end
26: end
27: end
This will attempt to determine the content type of the notification, unless one is already specified.
# File lib/mack-notifier/notifier.rb, line 61
61: def content_type
62: return @content_type unless @content_type.blank?
63: if has_attachments?
64: return "multipart/mixed"
65: elsif !body(:plain).blank? && !body(:html).blank?
66: return "multipart/alternative"
67: elsif body(:html)
68: return "text/html"
69: else
70: return "text/plain"
71: end
72: end
Returns the date sent, defaults to Time.now
# File lib/mack-notifier/notifier.rb, line 75
75: def date_sent
76: (@date_sent ||= Time.now)
77: end
Delivers the notification with the configured Mack::Notifier::DeliveryHandlers class. Returns false if there are any errors.
# File lib/mack-notifier/notifier.rb, line 103
103: def deliver(handler = deliver_with)
104: begin
105: deliver!(handler)
106: rescue Exception => e
107: return false
108: end
109: return true
110: end
Delivers the email with the configured Mack::Notifier::DeliveryHandlers class.
# File lib/mack-notifier/notifier.rb, line 113
113: def deliver!(handler = deliver_with)
114: "Mack::Notifier::DeliveryHandlers::#{handler.to_s.camelcase}".constantize.deliver(self)
115: end
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
# File lib/mack-notifier/notifier.rb, line 145
145: def deliver_with
146: configatron.mack.notifier.deliver_with
147: end
Returns a ready to be delivered, encoded, version of the notification.
# File lib/mack-notifier/notifier.rb, line 123
123: def deliverable(adap = adapter)
124: adap = "Mack::Notifier::Adapters::#{adap.to_s.camelcase}".constantize.new(self)
125: adap.convert
126: adap.deliverable
127: end
Returns true if there are attachments.
# File lib/mack-notifier/notifier.rb, line 92
92: def has_attachments?
93: !attachments.empty?
94: end
Returns the mime_version of the notification, defaults to "1.0"
# File lib/mack-notifier/notifier.rb, line 56
56: def mime_version
57: (@mime_version ||= "1.0")
58: end
Returns all the recipients of this notifier.
# File lib/mack-notifier/notifier.rb, line 118
118: def recipients
119: [self.to, self.cc, self.bcc].flatten.compact
120: end