Class: SplitIoClient::Engine::Parser::Evaluator
- Inherits:
-
Object
- Object
- SplitIoClient::Engine::Parser::Evaluator
- Defined in:
- lib/splitclient-rb/engine/parser/evaluator.rb
Instance Method Summary collapse
- #call(keys, split, attributes = nil) ⇒ Object
-
#initialize(segments_repository, splits_repository, config, multiple = false) ⇒ Evaluator
constructor
A new instance of Evaluator.
Constructor Details
#initialize(segments_repository, splits_repository, config, multiple = false) ⇒ Evaluator
Returns a new instance of Evaluator.
5 6 7 8 9 10 11 |
# File 'lib/splitclient-rb/engine/parser/evaluator.rb', line 5 def initialize(segments_repository, splits_repository, config, multiple = false) @splits_repository = splits_repository @segments_repository = segments_repository @multiple = multiple @config = config @cache = {} end |
Instance Method Details
#call(keys, split, attributes = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/splitclient-rb/engine/parser/evaluator.rb', line 13 def call(keys, split, attributes = nil) # DependencyMatcher here, split is actually a split_name in this case cache_result = split.is_a? String split = @splits_repository.get_split(split) if cache_result digest = Digest::MD5.hexdigest("#{{matching_key: keys[:matching_key]}}#{split}#{attributes}") if Models::Split.archived?(split) return treatment_hash(Models::Label::ARCHIVED, Models::Treatment::CONTROL, split[:changeNumber]) end treatment = if Models::Split.matchable?(split) if @multiple && @cache[digest] @cache[digest] else match(split, keys, attributes) end else treatment_hash(Models::Label::KILLED, split[:defaultTreatment], split[:changeNumber], split_configurations(split[:defaultTreatment], split)) end @cache[digest] = treatment if cache_result treatment end |