class MandrillQueue::Message::Recipients
Public Class Methods
new()
click to toggle source
# File lib/mandrill_queue/message/recipients.rb, line 78 def initialize @_recipients = [] end
Public Instance Methods
[](index)
click to toggle source
# 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)
click to toggle source
# 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
Also aliased as: dsl
empty?()
click to toggle source
# File lib/mandrill_queue/message/recipients.rb, line 86 def empty? @_recipients.empty? end
first()
click to toggle source
# File lib/mandrill_queue/message/recipients.rb, line 108 def first @_recipients.first end
last()
click to toggle source
# File lib/mandrill_queue/message/recipients.rb, line 112 def last @_recipients.last end
recipients()
click to toggle source
# File lib/mandrill_queue/message/recipients.rb, line 82 def recipients @_recipients end
set!(value, type = nil)
click to toggle source
# 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 = {})
click to toggle source
# File lib/mandrill_queue/message/recipients.rb, line 102 def to_a(options = {}) @_recipients.map do |r| r.to_hash(options) end end
validate(errors)
click to toggle source
# File lib/mandrill_queue/message/recipients.rb, line 146 def validate(errors) @_recipients.each do |r| r.validate(errors) end end
Protected Instance Methods
add_object(obj, email_field = :email, name_field = nil, type = nil, &block)
click to toggle source
# File lib/mandrill_queue/message/recipients.rb, line 154 def add_object(obj, email_field = :email, name_field = nil, type = nil, &block) args.first = [args.first] add_objects(*args, &block) end
add_objects(list, email_field = :email, name_field = nil, type = nil, &block)
click to toggle source
# File lib/mandrill_queue/message/recipients.rb, line 159 def add_objects(list, email_field = :email, name_field = nil, type = nil, &block) if block_given? list.each do |r| obj = Recipient.new obj.dsl(r, &block) obj.type(type) @_recipients << obj end else hashes = MandrillQueue::Message::Recipient::Helpers .objects_to_hashes(list, [email_field, name_field].compact) @_recipients += hashes.map do |h| Recipient.new(h[email_field], h[name_field], type, &block) end end end