Class: LaunchControl::MandrillContract

Inherits:
Object
  • Object
show all
Defined in:
lib/launch_control/mandrill_contract.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



8
9
10
# File 'lib/launch_control/mandrill_contract.rb', line 8

def errors
  @errors
end

Instance Method Details

#default_email_contractObject



57
58
59
60
61
62
# File 'lib/launch_control/mandrill_contract.rb', line 57

def default_email_contract
  {
    to:      lambda { |to| [Array,String,Hash].include?(to.class) },
    subject: 'string'
  }
end

#deliver(options) ⇒ Object



52
53
54
55
# File 'lib/launch_control/mandrill_contract.rb', line 52

def deliver(options)
  ActiveSupport::Deprecation.warn('deliver is deprecated. Use deliver! instead.')
  deliver!(options)
end

#deliver!(options) ⇒ Object

Raises:



45
46
47
48
49
50
# File 'lib/launch_control/mandrill_contract.rb', line 45

def deliver!(options)
  options = merged_options(options)
  launch = LaunchControl::Mailer.new(template, options)
  raise ContractFailure.new(error_string) unless valid?(options) && launch.valid?
  valid?(options) && launch.valid? && launch.deliver
end

#error_stringObject



74
75
76
77
78
# File 'lib/launch_control/mandrill_contract.rb', line 74

def error_string
  (@errors || {}).map { |(attr, message)|
    "#{attr} #{message}"
  }.join(', ')
end

#merged_contractObject

Override these to control how your validations and merge variables get integrated with Launch Control defaults. For example:

def merged_options(options)
  options.merge(to_json)
end

This allows you to wrap any custom merge vars into a to_json method for a cleaner interaction.



37
38
39
# File 'lib/launch_control/mandrill_contract.rb', line 37

def merged_contract
  default_email_contract.merge!(validations)
end

#merged_options(options) ⇒ Object



41
42
43
# File 'lib/launch_control/mandrill_contract.rb', line 41

def merged_options(options)
  options
end

#templateObject

Override this with your template id from Mandrill.



21
22
23
# File 'lib/launch_control/mandrill_contract.rb', line 21

def template
  raise 'You must define a Mandrill template to use'
end

#valid?(options) ⇒ Boolean



64
65
66
67
68
69
70
71
72
# File 'lib/launch_control/mandrill_contract.rb', line 64

def valid?(options)
  validator = HashValidator.validate(options, merged_contract)
  if validator.valid?
    true
  else
    @errors = validator.errors
    false
  end
end

#validationsObject

Override this with any custom validations you wish to perform on your mail object before delivering.



14
15
16
# File 'lib/launch_control/mandrill_contract.rb', line 14

def validations
  {}
end