Class: MandrillQueue::Message::Recipients
- Inherits:
-
Object
- Object
- MandrillQueue::Message::Recipients
- Defined in:
- lib/mandrill_queue/message/recipients.rb
Defined Under Namespace
Modules: DSL Classes: Recipient
Instance Method Summary collapse
- #[](index) ⇒ Object
- #add(email = nil, name = nil, name_field = nil, type = nil, &block) ⇒ Object (also: #dsl)
- #empty? ⇒ Boolean
- #first ⇒ Object
-
#initialize ⇒ Recipients
constructor
A new instance of Recipients.
- #last ⇒ Object
- #recipients ⇒ Object
- #set!(value, type = nil) ⇒ Object
- #to_a(options = {}) ⇒ Object
- #validate(errors) ⇒ Object
Constructor Details
#initialize ⇒ Recipients
Returns a new instance of Recipients.
78 79 80 |
# File 'lib/mandrill_queue/message/recipients.rb', line 78 def initialize @_recipients = [] end |
Instance Method Details
#[](index) ⇒ Object
116 117 118 |
# File 'lib/mandrill_queue/message/recipients.rb', line 116 def [](index) @_recipients[index] end |
#add(email = nil, name = nil, name_field = nil, type = nil, &block) ⇒ Object Also known as: dsl
90 91 92 93 94 95 96 97 98 |
# File 'lib/mandrill_queue/message/recipients.rb', line 90 def add(email = nil, name = nil, name_field = nil, type = nil, &block) if email.respond_to?(:each) add_objects(email, name, name_field, type, &block) elsif !email.is_a?(String) add_objects([email], name, name_field, type, &block) else @_recipients << Recipient.new(email, name, type, &block) end end |
#empty? ⇒ Boolean
86 87 88 |
# File 'lib/mandrill_queue/message/recipients.rb', line 86 def empty? @_recipients.empty? end |
#first ⇒ Object
108 109 110 |
# File 'lib/mandrill_queue/message/recipients.rb', line 108 def first @_recipients.first end |
#last ⇒ Object
112 113 114 |
# File 'lib/mandrill_queue/message/recipients.rb', line 112 def last @_recipients.last end |
#recipients ⇒ Object
82 83 84 |
# File 'lib/mandrill_queue/message/recipients.rb', line 82 def recipients @_recipients end |
#set!(value, type = nil) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/mandrill_queue/message/recipients.rb', line 120 def set!(value, type = nil) value = [value] unless value.is_a?(Array) @_recipients = value.map do |recipient| obj = Recipient.new case recipient when String obj.email recipient raise MessageError, "Must specify a recipient type when calling set! with a string on recipient." if type.nil? obj.type type unless type.nil? when Hash recipient.symbolize_keys! raise MessageError, "#{recipient} must contain email address" if recipient[:email].nil? obj.set!(recipient) obj.type type if obj.type.nil? && !type.nil? else raise MessageError, "#{recipient} is an invalid recipient." end obj end self end |
#to_a(options = {}) ⇒ Object
102 103 104 105 106 |
# File 'lib/mandrill_queue/message/recipients.rb', line 102 def to_a( = {}) @_recipients.map do |r| r.to_hash() end end |
#validate(errors) ⇒ Object
146 147 148 149 150 |
# File 'lib/mandrill_queue/message/recipients.rb', line 146 def validate(errors) @_recipients.each do |r| r.validate(errors) end end |