Class: Outbox::Message
- Inherits:
-
Object
- Object
- Outbox::Message
- Includes:
- MessageTypes
- Defined in:
- lib/outbox/message.rb
Instance Method Summary collapse
-
#deliver(audience) ⇒ Object
Delivers all of the messages to the given ‘audience’.
-
#initialize(message_type_values = nil, &block) ⇒ Message
constructor
Make a new message.
Methods included from MessageTypes
Constructor Details
#initialize(message_type_values = nil, &block) ⇒ Message
18 19 20 21 22 23 24 |
# File 'lib/outbox/message.rb', line 18 def initialize( = nil, &block) if block_given? instance_eval(&block) else () unless .nil? end end |
Instance Method Details
#deliver(audience) ⇒ Object
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.
.deliver email: '[email protected]', sms: '+15555555555'
audience = OpenStruct.new
audience.email = '[email protected]'
audience.sms = '+15555555555'
.deliver(audience)
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/outbox/message.rb', line 35 def deliver(audience) audience = Outbox::Accessor.new(audience) self.class..each_key do || = self.public_send() next if .nil? recipient = audience[] .deliver(recipient) if recipient end end |