Class: SesDashboard::ForwardRule
- Inherits:
-
Object
- Object
- SesDashboard::ForwardRule
- Defined in:
- lib/ses_dashboard/forward_rule.rb
Overview
Evaluates a single forwarding rule against a WebhookProcessor::Result.
A rule is a Hash with three keys:
"field" — which Result attribute to test
"operator" — how to compare
"value" — what to compare against
Supported fields:
"event_type" — string ("bounce", "delivery", "complaint", …)
"source" — string (From: address)
"destination" — array (To: addresses — rule passes if ANY element matches)
"subject" — string (email subject)
Supported operators:
"in" — field value is included in the given array
"not_in" — field value is NOT included in the given array
"eq" — exact string equality
"not_eq" — string inequality
"starts_with" — prefix match (for arrays: any element matches)
"ends_with" — suffix match (for arrays: any element matches)
"contains" — substring match (for arrays: any element matches)
New fields/operators can be added by extending the private methods below.
Instance Method Summary collapse
-
#initialize(rule_hash) ⇒ ForwardRule
constructor
A new instance of ForwardRule.
- #match?(result) ⇒ Boolean
Constructor Details
#initialize(rule_hash) ⇒ ForwardRule
Returns a new instance of ForwardRule.
27 28 29 30 31 |
# File 'lib/ses_dashboard/forward_rule.rb', line 27 def initialize(rule_hash) @field = (rule_hash["field"] || rule_hash[:field]).to_s @operator = (rule_hash["operator"] || rule_hash[:operator]).to_s @value = rule_hash["value"] || rule_hash[:value] end |
Instance Method Details
#match?(result) ⇒ Boolean
33 34 35 36 |
# File 'lib/ses_dashboard/forward_rule.rb', line 33 def match?(result) field_value = extract_field(result) evaluate(field_value) end |