Class: Evaluator
- Inherits:
-
Evaluation
- Object
- Evaluation
- Evaluator
- Defined in:
- lib/ff/ruby/server/sdk/api/evaluator.rb
Instance Method Summary collapse
- #bool_variation(identifier, target, default_value, callback) ⇒ Object
- #evaluate(identifier, target, expected, callback) ⇒ Object
-
#initialize(repository, logger = nil) ⇒ Evaluator
constructor
A new instance of Evaluator.
- #integer_variation(identifier, target, default_value, callback) ⇒ Object
- #json_variation(identifier, target, default_value, callback) ⇒ Object
- #number_variation(identifier, target, default_value, callback) ⇒ Object
- #string_variation(identifier, target, default_value, callback) ⇒ Object
Constructor Details
#initialize(repository, logger = nil) ⇒ Evaluator
Returns a new instance of Evaluator.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ff/ruby/server/sdk/api/evaluator.rb', line 10 def initialize(repository, logger = nil) unless repository.kind_of?(Repository) raise "The 'repository' parameter must be of '" + Repository.to_s + "' data type" end if logger != nil @logger = logger else @logger = Logger.new(STDOUT) end @repository = repository end |
Instance Method Details
#bool_variation(identifier, target, default_value, callback) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ff/ruby/server/sdk/api/evaluator.rb', line 25 def bool_variation(identifier, target, default_value, callback) variation = evaluate(identifier, target, "boolean", callback) if variation != nil return variation.value == "true" end SdkCodes::warn_default_variation_served @logger, identifier, target, default_value.to_s default_value end |
#evaluate(identifier, target, expected, callback) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/ff/ruby/server/sdk/api/evaluator.rb', line 84 def evaluate(identifier, target, expected, callback) if callback != nil unless callback.kind_of?(FlagEvaluateCallback) raise "The 'callback' parameter must be of '" + FlagEvaluateCallback.to_s + "' data type" end end flag = @repository.get_flag(identifier) if flag != nil && flag.kind == expected unless flag.prerequisites.empty? pre_req = check_pre_requisite(flag, target) unless pre_req return find_variation(flag.variations, flag.off_variation) end end variation = evaluate_flag(flag, target) if variation != nil if callback != nil callback.process_evaluation(flag, target, variation) end return variation end end nil end |
#integer_variation(identifier, target, default_value, callback) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ff/ruby/server/sdk/api/evaluator.rb', line 49 def integer_variation(identifier, target, default_value, callback) variation = evaluate(identifier, target, "int", callback) if variation != nil return variation.value.to_i end SdkCodes::warn_default_variation_served @logger, identifier, target, default_value.to_s default_value end |
#json_variation(identifier, target, default_value, callback) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ff/ruby/server/sdk/api/evaluator.rb', line 72 def json_variation(identifier, target, default_value, callback) variation = evaluate(identifier, target, "json", callback) if variation != nil return JSON.parse(variation.value) end SdkCodes::warn_default_variation_served @logger, identifier, target, default_value.to_s default_value end |
#number_variation(identifier, target, default_value, callback) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ff/ruby/server/sdk/api/evaluator.rb', line 61 def number_variation(identifier, target, default_value, callback) variation = evaluate(identifier, target, "int", callback) if variation != nil return variation.value.to_f end SdkCodes::warn_default_variation_served @logger, identifier, target, default_value.to_s default_value end |
#string_variation(identifier, target, default_value, callback) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ff/ruby/server/sdk/api/evaluator.rb', line 37 def string_variation(identifier, target, default_value, callback) variation = evaluate(identifier, target, "string", callback) if variation != nil return variation.value end SdkCodes::warn_default_variation_served @logger, identifier, target, default_value.to_s default_value end |