Class: MandrillQueue::Message::Recipients::Recipient

Inherits:
Object
  • Object
show all
Defined in:
lib/mandrill_queue/message/recipients.rb

Constant Summary collapse

ACCESSORS =
[:type, :name, :email]

Instance Method Summary collapse

Constructor Details

#initialize(email = nil, name = nil, type = nil, &block) ⇒ Recipient

Returns a new instance of Recipient.



32
33
34
35
36
37
38
# File 'lib/mandrill_queue/message/recipients.rb', line 32

def initialize(email = nil, name = nil, type = nil, &block)
	@type = type
	@name = name
	@email = email

	instance_eval(&block) if block_given?
end

Instance Method Details

#set!(hash) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/mandrill_queue/message/recipients.rb', line 52

def set!(hash)
	ACCESSORS.each do |key|
		instance_variable_set("@#{key}".to_sym, hash[key])
	end

	self
end

#to_hash(options = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/mandrill_queue/message/recipients.rb', line 60

def to_hash(options = {})
	hash = {}
	ACCESSORS.each do |key|
		value = send(key)
		if options[:include_nils] || !value.nil?
			hash[key] = value.nil? ? nil : value.to_s
		end
	end
	hash
end

#validate(errors) ⇒ Object



71
72
73
# File 'lib/mandrill_queue/message/recipients.rb', line 71

def validate(errors)
	errors.push([@type, "Email must be set for recipient."]) if email.nil?
end