Class: LaunchControl::MandrillContract
- Inherits:
-
Object
- Object
- LaunchControl::MandrillContract
- Defined in:
- lib/launch_control/mandrill_contract.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
Instance Method Summary collapse
- #default_email_contract ⇒ Object
- #defaults ⇒ Object
- #deliver(options) ⇒ Object
- #deliver!(options = {}) ⇒ Object
- #error_string ⇒ Object
-
#merged_contract ⇒ Object
Override these to control how your validations and merge variables get integrated with Launch Control defaults.
- #merged_options(options) ⇒ Object
- #string_present? ⇒ Boolean
-
#template ⇒ Object
Override this with your template id from Mandrill.
- #valid?(options = {}) ⇒ Boolean
-
#validations ⇒ Object
Override this with any custom validations you wish to perform on your mail object before delivering.
Instance Attribute Details
#errors ⇒ Object
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_contract ⇒ Object
60 61 62 63 64 65 |
# File 'lib/launch_control/mandrill_contract.rb', line 60 def default_email_contract # Note that subject is not required as it can be set in Mandrill { to: lambda { |to| [Array,String,Hash].include?(to.class) && to.present? } } end |
#defaults ⇒ Object
41 42 43 |
# File 'lib/launch_control/mandrill_contract.rb', line 41 def defaults {} end |
#deliver(options) ⇒ Object
55 56 57 58 |
# File 'lib/launch_control/mandrill_contract.rb', line 55 def deliver() ActiveSupport::Deprecation.warn('deliver is deprecated. Use deliver! instead.') deliver!() end |
#deliver!(options = {}) ⇒ Object
49 50 51 52 53 |
# File 'lib/launch_control/mandrill_contract.rb', line 49 def deliver!( = {}) launch = LaunchControl::Mailer.new(template, ()) raise ContractFailure.new(error_string) unless valid?() && launch.valid? launch.deliver end |
#error_string ⇒ Object
78 79 80 81 82 |
# File 'lib/launch_control/mandrill_contract.rb', line 78 def error_string (@errors || {}).map { |(attr, )| "#{attr} #{message}" }.join(', ') end |
#merged_contract ⇒ Object
Override these to control how your validations and merge variables get integrated with Launch Control defaults. For example:
def ()
.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
45 46 47 |
# File 'lib/launch_control/mandrill_contract.rb', line 45 def () defaults.merge() end |
#string_present? ⇒ Boolean
84 85 86 |
# File 'lib/launch_control/mandrill_contract.rb', line 84 def string_present? lambda { |value| value.class == String && value.present? } end |
#template ⇒ Object
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
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/launch_control/mandrill_contract.rb', line 67 def valid?( = {}) = () validator = HashValidator.validate(, merged_contract) if validator.valid? true else @errors = validator.errors false end end |
#validations ⇒ Object
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 |