lib/outbox/message.rb in outbox-0.1.0 vs lib/outbox/message.rb in outbox-0.1.1
- old
+ new
@@ -21,10 +21,19 @@
else
assign_message_type_values(message_type_values) unless message_type_values.nil?
end
end
+ # Loops through each registered message type and sets the content body.
+ def body(value)
+ each_message_type do |message_type, message|
+ next if message.nil?
+ message.body = value
+ end
+ end
+ alias :body= :body
+
# Delivers all of the messages to the given 'audience'. An 'audience' object
# can be a hash or an object that responds to the current message types. Only
# the message types specified in the 'audience' object will be sent to.
#
# message.deliver email: 'hello@example.com', sms: '+15555555555'
@@ -33,11 +42,10 @@
# audience.sms = '+15555555555'
# message.deliver(audience)
def deliver(audience)
audience = Outbox::Accessor.new(audience)
- self.class.message_types.each_key do |message_type|
- message = self.public_send(message_type)
+ each_message_type do |message_type, message|
next if message.nil?
recipient = audience[message_type]
message.deliver(recipient) if recipient
end