Class: Mammoth::RouteFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/mammoth/route_filter.rb

Overview

Matches CDC events and transaction envelopes against destination route rules.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#operationsObject (readonly)

Returns the value of attribute operations.



6
7
8
# File 'lib/mammoth/route_filter.rb', line 6

def operations
  @operations
end

#schemasObject (readonly)

Returns the value of attribute schemas.



6
7
8
# File 'lib/mammoth/route_filter.rb', line 6

def schemas
  @schemas
end

#tablesObject (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

Returns:

  • (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

Returns:

  • (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