Class: Outbox::Message
- Inherits:
-
Object
- Object
- Outbox::Message
- Includes:
- MessageTypes
- Defined in:
- lib/outbox/message.rb
Class Method Summary collapse
-
.use_test_client ⇒ Object
Use the Outbox::Clients::TestClient for all message types.
Instance Method Summary collapse
-
#body(value) ⇒ Object
(also: #body=)
Loops through each registered message type and sets the content body.
-
#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
#assign_message_type_values, #each_message_type, included
Constructor Details
#initialize(message_type_values = nil, &block) ⇒ Message
27 28 29 30 31 32 33 |
# File 'lib/outbox/message.rb', line 27 def initialize( = nil, &block) if block_given? instance_eval(&block) elsif () end end |
Class Method Details
.use_test_client ⇒ Object
Use the Outbox::Clients::TestClient for all message types. This is useful for testing or working an a development environment.
10 11 12 13 14 |
# File 'lib/outbox/message.rb', line 10 def self.use_test_client .each_value do || .default_client(:test) end end |
Instance Method Details
#body(value) ⇒ Object Also known as: body=
Loops through each registered message type and sets the content body.
36 37 38 39 40 41 |
# File 'lib/outbox/message.rb', line 36 def body(value) do |_, | next if .nil? .body = value end end |
#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)
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/outbox/message.rb', line 54 def deliver(audience) audience = Outbox::Accessor.new(audience) do |, | next if .nil? recipient = audience[] .deliver(recipient) if recipient end end |