class MandrillQueue::Message::Internal
Constants
- ACCESSORS
- EXTERNAL_ACCESSORS
Public Class Methods
new(values = nil)
click to toggle source
# File lib/mandrill_queue/message.rb, line 36 def initialize(values = nil) set!(values) unless values.nil? end
Public Instance Methods
content_message?()
click to toggle source
# File lib/mandrill_queue/message.rb, line 79 def content_message? !html.blank? || !text.blank? end
load_attachments!()
click to toggle source
# File lib/mandrill_queue/message.rb, line 95 def load_attachments! @_attachments.load_all unless @_attachments.nil? @_images.load_all unless @_images.nil? self end
nillify!()
click to toggle source
# File lib/mandrill_queue/message.rb, line 54 def nillify! transform_accessors! { |k| nil } EXTERNAL_ACCESSORS.each do |key| instance_variable_set("@_#{key}", nil) end @_recipients = nil self end
set!(values)
click to toggle source
# File lib/mandrill_queue/message.rb, line 65 def set!(values) nillify! values.to_hash.symbolize_keys! transform_accessors! { |k| values[k] } EXTERNAL_ACCESSORS.each do |key| send(key).set!(values[key]) unless values[key].nil? end [:to, :cc, :bcc].each do |key| recipients.set!(values[key], key) if values[key] end end
to_hash(options = {})
click to toggle source
# File lib/mandrill_queue/message.rb, line 105 def to_hash(options = {}) hash = {} hash[:to] = recipients.to_a(options) if @_recipients ACCESSORS.each do |key| value = instance_variable_get("@#{key}") next if value.nil? && !options[:include_nils] hash[key] = value.respond_to?(:to_hash) ? value.to_hash : value end EXTERNAL_ACCESSORS.each do |key| sym = "@_#{key}".to_sym var = instance_variable_get(sym) if options[:include_nils] || !var.nil? if var.is_a?(Variables::Internal) hash[key] = var.to_key_value_array(options) else hash[key] = (var.to_hash(options) rescue var.to_a(options) rescue var) end end end hash end
to_json(options = {})
click to toggle source
# File lib/mandrill_queue/message.rb, line 101 def to_json(options = {}) to_hash(options).to_json end
validate(errors)
click to toggle source
# File lib/mandrill_queue/message.rb, line 83 def validate(errors) errors.push([:message, "Please specify at least one recipient."]) if to.empty? EXTERNAL_ACCESSORS.each do |key| sym = "@_#{key}" val = instance_variable_get(sym) val.validate(errors) unless val.nil? || !val.respond_to?(:validate) end recipients.validate(errors) end
Protected Instance Methods
transform_accessors!() { |key| ... }
click to toggle source
# File lib/mandrill_queue/message.rb, line 132 def transform_accessors! ACCESSORS.each do |key| sym = "@#{key}".to_sym instance_variable_set(sym, yield(key)) end end