Class: Siftly::Config
- Inherits:
-
Object
- Object
- Siftly::Config
- Defined in:
- lib/siftly/config.rb
Instance Attribute Summary collapse
-
#aggregator ⇒ Object
Returns the value of attribute aggregator.
-
#enabled_filters ⇒ Object
readonly
Returns the value of attribute enabled_filters.
-
#failure_mode ⇒ Object
Returns the value of attribute failure_mode.
-
#instrumenter ⇒ Object
Returns the value of attribute instrumenter.
-
#threshold ⇒ Object
Returns the value of attribute threshold.
Instance Method Summary collapse
- #dup ⇒ Object
- #filter(key) {|filter_config| ... } ⇒ Object
- #filter_config_for(key) ⇒ Object
- #filter_configs ⇒ Object
-
#initialize(enabled_filters: [], filter_configs: {}, aggregator: :score, threshold: 1.0, failure_mode: :record, instrumenter: nil) ⇒ Config
constructor
A new instance of Config.
- #use(key) ⇒ Object
Constructor Details
#initialize(enabled_filters: [], filter_configs: {}, aggregator: :score, threshold: 1.0, failure_mode: :record, instrumenter: nil) ⇒ Config
Returns a new instance of Config.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/siftly/config.rb', line 8 def initialize( enabled_filters: [], filter_configs: {}, aggregator: :score, threshold: 1.0, failure_mode: :record, instrumenter: nil ) @enabled_filters = enabled_filters.map(&:to_sym) @filter_configs = normalize_filter_configs(filter_configs) @aggregator = aggregator @threshold = threshold @failure_mode = failure_mode @instrumenter = instrumenter end |
Instance Attribute Details
#aggregator ⇒ Object
Returns the value of attribute aggregator.
5 6 7 |
# File 'lib/siftly/config.rb', line 5 def aggregator @aggregator end |
#enabled_filters ⇒ Object (readonly)
Returns the value of attribute enabled_filters.
6 7 8 |
# File 'lib/siftly/config.rb', line 6 def enabled_filters @enabled_filters end |
#failure_mode ⇒ Object
Returns the value of attribute failure_mode.
5 6 7 |
# File 'lib/siftly/config.rb', line 5 def failure_mode @failure_mode end |
#instrumenter ⇒ Object
Returns the value of attribute instrumenter.
5 6 7 |
# File 'lib/siftly/config.rb', line 5 def instrumenter @instrumenter end |
#threshold ⇒ Object
Returns the value of attribute threshold.
5 6 7 |
# File 'lib/siftly/config.rb', line 5 def threshold @threshold end |
Instance Method Details
#dup ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/siftly/config.rb', line 45 def dup self.class.new( enabled_filters: enabled_filters.dup, filter_configs: filter_configs.transform_values(&:to_h), aggregator: aggregator, threshold: threshold, failure_mode: failure_mode, instrumenter: instrumenter ) end |
#filter(key) {|filter_config| ... } ⇒ Object
30 31 32 33 34 |
# File 'lib/siftly/config.rb', line 30 def filter(key) filter_config = (@filter_configs[key.to_sym] ||= FilterConfig.new(key)) yield(filter_config) if block_given? filter_config end |
#filter_config_for(key) ⇒ Object
36 37 38 39 |
# File 'lib/siftly/config.rb', line 36 def filter_config_for(key) existing = @filter_configs[key.to_sym] existing ? existing.merge({}) : FilterConfig.new(key) end |
#filter_configs ⇒ Object
41 42 43 |
# File 'lib/siftly/config.rb', line 41 def filter_configs @filter_configs.transform_values { |config| config.merge({}) } end |
#use(key) ⇒ Object
24 25 26 27 28 |
# File 'lib/siftly/config.rb', line 24 def use(key) key = key.to_sym @enabled_filters << key unless @enabled_filters.include?(key) key end |