Class: MandrillQueue::Message::Recipient::Variable

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

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(recipient = nil, *args, &block) ⇒ Variable

Returns a new instance of Variable.



14
15
16
17
# File 'lib/mandrill_queue/message/recipient/variable.rb', line 14

def initialize(recipient = nil, *args, &block)
	@_recipient = recipient
	dsl(&block) if block_given?
end

Class Attribute Details

.var_nameObject (readonly)

Returns the value of attribute var_name.



6
7
8
# File 'lib/mandrill_queue/message/recipient/variable.rb', line 6

def var_name
  @var_name
end

Class Method Details

.variables(name) ⇒ Object



8
9
10
11
# File 'lib/mandrill_queue/message/recipient/variable.rb', line 8

def variables(name)
	@var_name = name
	Variables::DSL.include_as(self, name)
end

Instance Method Details

#dsl(&block) ⇒ Object



60
61
62
# File 'lib/mandrill_queue/message/recipient/variable.rb', line 60

def dsl(&block)
	send(var_name).dsl(&block)
end

#recipient(value = nil) ⇒ Object



27
28
29
30
# File 'lib/mandrill_queue/message/recipient/variable.rb', line 27

def recipient(value = nil)
	@_recipient = value unless value.nil?
	@_recipient
end

#recipient=(value) ⇒ Object



23
24
25
# File 'lib/mandrill_queue/message/recipient/variable.rb', line 23

def recipient=(value)
	@_recipient = value
end

#set!(hash) ⇒ Object



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

def set!(hash)
	@_recipient = hash[:rcpt]
	var_instance_set(nil)
	send(var_name).set!(hash[var_name]) unless hash[var_name].nil?
	self
end

#to_hash(options = {}) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/mandrill_queue/message/recipient/variable.rb', line 44

def to_hash(options = {})
	hash = {}
	hash[:rcpt] = recipient if options[:include_nils] || !recipient.nil?
	if options[:include_nils] || var_instance
		hash[var_name] = send(var_name).to_key_value_array(options)
	end
	hash
end

#validate(errors, options = {}) ⇒ Object



64
65
66
67
# File 'lib/mandrill_queue/message/recipient/variable.rb', line 64

def validate(errors, options = {})
	cn = options[:as] || self.class.name.underscore.split('/').last.to_sym
	errors.push([cn, "Recipient cannot be empty."]) if recipient.blank?
end

#var_instanceObject



32
33
34
# File 'lib/mandrill_queue/message/recipient/variable.rb', line 32

def var_instance
	instance_variable_get("@_#{var_name}".to_sym)
end

#var_instance_set(value) ⇒ Object



40
41
42
# File 'lib/mandrill_queue/message/recipient/variable.rb', line 40

def var_instance_set(value)
	instance_variable_set("@_#{var_name}".to_sym, value)
end

#var_nameObject



19
20
21
# File 'lib/mandrill_queue/message/recipient/variable.rb', line 19

def var_name
	self.class.var_name
end

#variablesObject



36
37
38
# File 'lib/mandrill_queue/message/recipient/variable.rb', line 36

def variables
	send(var_name)
end