Class: Mammoth::RouteFilter
- Inherits:
-
Object
- Object
- Mammoth::RouteFilter
- Defined in:
- lib/mammoth/route_filter.rb
Overview
Matches CDC events and transaction envelopes against destination route rules.
Instance Attribute Summary collapse
-
#operations ⇒ Object
readonly
Returns the value of attribute operations.
-
#schemas ⇒ Object
readonly
Returns the value of attribute schemas.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
Instance Method Summary collapse
-
#initialize(config = nil) ⇒ RouteFilter
constructor
A new instance of RouteFilter.
- #match?(work, serializer:) ⇒ Boolean
- #match_payload?(payload) ⇒ Boolean
Constructor Details
#initialize(config = nil) ⇒ RouteFilter
Returns a new instance of RouteFilter.
8 9 10 11 12 13 |
# File 'lib/mammoth/route_filter.rb', line 8 def initialize(config = nil) route = config || {} @schemas = normalized_set(route["schemas"]) @tables = normalized_set(route["tables"]) @operations = normalized_set(route["operations"]) end |
Instance Attribute Details
#operations ⇒ Object (readonly)
Returns the value of attribute operations.
6 7 8 |
# File 'lib/mammoth/route_filter.rb', line 6 def operations @operations end |
#schemas ⇒ Object (readonly)
Returns the value of attribute schemas.
6 7 8 |
# File 'lib/mammoth/route_filter.rb', line 6 def schemas @schemas end |
#tables ⇒ Object (readonly)
Returns the value of attribute tables.
6 7 8 |
# File 'lib/mammoth/route_filter.rb', line 6 def tables @tables end |
Instance Method Details
#match?(work, serializer:) ⇒ Boolean
15 16 17 |
# File 'lib/mammoth/route_filter.rb', line 15 def match?(work, serializer:) match_payload?(serializer.call(work)) end |
#match_payload?(payload) ⇒ Boolean
19 20 21 22 23 24 25 |
# File 'lib/mammoth/route_filter.rb', line 19 def match_payload?(payload) if transaction_payload?(payload) payload.fetch("events").any? { |event| event_match?(event) } else event_match?(payload) end end |