class Outbox::Message
Public Class Methods
new(message_type_values = nil, &block)
click to toggle source
Make a new message. Every message can be created using a hash, block, or direct assignment.
message = Message.new do email do subject 'Subject' end end message = Message.new email: { subject: 'Subject' } message = Message.new message.email = Email.new subject: 'Subject'
# File lib/outbox/message.rb, line 27 def initialize(message_type_values = nil, &block) if block_given? instance_eval(&block) elsif message_type_values assign_message_type_values(message_type_values) end end
use_test_client()
click to toggle source
Use the Outbox::Clients::TestClient
for all message types. This is useful for testing or working an a development environment.
# File lib/outbox/message.rb, line 10 def self.use_test_client message_types.each_value do |message_type| message_type.default_client(:test) end end
Public Instance Methods
body(value)
click to toggle source
Loops through each registered message type and sets the content body.
# File lib/outbox/message.rb, line 36 def body(value) each_message_type do |_, message| next if message.nil? message.body = value end end
Also aliased as: body=
deliver(audience)
click to toggle source
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' audience = OpenStruct.new audience.email = 'hello@example.com' audience.sms = '+15555555555' message.deliver(audience)
# File lib/outbox/message.rb, line 54 def deliver(audience) audience = Outbox::Accessor.new(audience) each_message_type do |message_type, message| next if message.nil? recipient = audience[message_type] message.deliver(recipient) if recipient end end