Class: Siftly::Pipeline
- Inherits:
-
Object
- Object
- Siftly::Pipeline
- Defined in:
- lib/siftly/pipeline.rb
Constant Summary collapse
- VALID_FAILURE_MODES =
%i[record open closed raise].freeze
Instance Method Summary collapse
- #call(value:, attribute: nil, record: nil, context: {}) ⇒ Object
-
#initialize(filter_keys:, filter_configs:, aggregator:, threshold:, failure_mode:, instrumenter:) ⇒ Pipeline
constructor
A new instance of Pipeline.
Constructor Details
#initialize(filter_keys:, filter_configs:, aggregator:, threshold:, failure_mode:, instrumenter:) ⇒ Pipeline
Returns a new instance of Pipeline.
7 8 9 10 11 12 13 14 |
# File 'lib/siftly/pipeline.rb', line 7 def initialize(filter_keys:, filter_configs:, aggregator:, threshold:, failure_mode:, instrumenter:) @filter_keys = filter_keys.map(&:to_sym) @filter_configs = filter_configs @aggregator = aggregator @threshold = threshold.to_f @failure_mode = normalize_failure_mode(failure_mode) @instrumenter = instrumenter || Instrumentation::NullInstrumenter.new end |
Instance Method Details
#call(value:, attribute: nil, record: nil, context: {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/siftly/pipeline.rb', line 16 def call(value:, attribute: nil, record: nil, context: {}) filter_results = filter_keys.map do |filter_key| run_filter(filter_key, value: value, attribute: attribute, record: record, context: context) end aggregation = resolve_aggregator.call( filter_results: filter_results, threshold: threshold, context: { value: value, attribute: attribute, record: record, context: context } ) result = Result.new( spam: aggregation.fetch(:spam), score: aggregation.fetch(:score), filter_results: filter_results, reasons: filter_results.map(&:reason).compact, attribute: attribute, value_preview: preview(value), threshold: threshold, aggregator: aggregator_name ) instrumenter.instrument( "siftly.pipeline.completed", attribute: attribute, filter_count: filter_keys.length, matched_filters: result.matches.map(&:filter), spam: result.spam?, score: result.score ) result end |