Class: CDC::Core::Filter
- Inherits:
-
Object
- Object
- CDC::Core::Filter
- Defined in:
- lib/cdc/core/filter.rb
Overview
Predicate object used to decide whether a pipeline should process an event.
Filters are composable with #& and #|. A filter only matches when its predicate returns true exactly, keeping accidental truthy values from silently passing events through a pipeline.
Class Method Summary collapse
-
.all ⇒ Filter
Match every event.
-
.operation(operation) ⇒ Filter
Match events by operation.
-
.qualified_table(name) ⇒ Filter
Match events from a fully qualified schema.table name.
-
.schema(name) ⇒ Filter
Match events from a schema.
-
.table(name) ⇒ Filter
Match events from a table regardless of schema.
Instance Method Summary collapse
-
#&(other) ⇒ Filter
Compose this filter with another filter using logical AND.
-
#initialize {|event| ... } ⇒ Filter
constructor
Build a custom filter.
-
#match?(event) ⇒ Boolean
(also: #=~)
Whether this filter matches an event.
-
#|(other) ⇒ Filter
Compose this filter with another filter using logical OR.
Constructor Details
#initialize {|event| ... } ⇒ Filter
Build a custom filter.
45 46 47 48 49 |
# File 'lib/cdc/core/filter.rb', line 45 def initialize(&predicate) raise ArgumentError, 'predicate block required' unless predicate @predicate = predicate end |
Class Method Details
.all ⇒ Filter
Match every event.
14 |
# File 'lib/cdc/core/filter.rb', line 14 def self.all = new { |_event| true } |
.operation(operation) ⇒ Filter
Match events by operation.
38 |
# File 'lib/cdc/core/filter.rb', line 38 def self.operation(operation) = new { |event| event.operation == Operation.normalize(operation) } |
.qualified_table(name) ⇒ Filter
Match events from a fully qualified schema.table name.
32 |
# File 'lib/cdc/core/filter.rb', line 32 def self.qualified_table(name) = new { |event| event.qualified_table_name == name.to_s } |
.schema(name) ⇒ Filter
Match events from a schema.
20 |
# File 'lib/cdc/core/filter.rb', line 20 def self.schema(name) = new { |event| event.schema == name.to_s } |
.table(name) ⇒ Filter
Match events from a table regardless of schema.
26 |
# File 'lib/cdc/core/filter.rb', line 26 def self.table(name) = new { |event| event.table == name.to_s } |
Instance Method Details
#&(other) ⇒ Filter
Compose this filter with another filter using logical AND.
64 65 66 |
# File 'lib/cdc/core/filter.rb', line 64 def &(other) self.class.new { |event| match?(event) && other.match?(event) } end |
#match?(event) ⇒ Boolean Also known as: =~
Whether this filter matches an event.
55 56 57 |
# File 'lib/cdc/core/filter.rb', line 55 def match?(event) @predicate.call(event) == true end |
#|(other) ⇒ Filter
Compose this filter with another filter using logical OR.
72 73 74 |
# File 'lib/cdc/core/filter.rb', line 72 def |(other) self.class.new { |event| match?(event) || other.match?(event) } end |