@@ -5,9 +5,6 @@ module SDK
5
5
# TODO: Write documentation
6
6
#
7
7
class Client
8
- RESULT_TYPE = %i[ boolean string number integer float object ] . freeze
9
- SUFFIXES = %i[ value details ] . freeze
10
-
11
8
attr_reader :metadata , :evaluation_context
12
9
13
10
attr_accessor :hooks
@@ -19,20 +16,63 @@ def initialize(provider:, domain: nil, evaluation_context: nil)
19
16
@hooks = [ ]
20
17
end
21
18
22
- RESULT_TYPE . each do |result_type |
23
- SUFFIXES . each do |suffix |
24
- class_eval <<-RUBY , __FILE__ , __LINE__ + 1
25
- # def fetch_boolean_details(flag_key:, default_value:, evaluation_context: nil)
26
- # result = @provider.fetch_boolean_value(flag_key: flag_key, default_value: default_value, evaluation_context: evaluation_context)
27
- # end
28
- def fetch_#{ result_type } _#{ suffix } (flag_key:, default_value:, evaluation_context: nil)
29
- built_context = EvaluationContextBuilder.new.call(api_context: OpenFeature::SDK.evaluation_context, client_context: self.evaluation_context, invocation_context: evaluation_context)
30
- resolution_details = @provider.fetch_#{ result_type } _value(flag_key:, default_value:, evaluation_context: built_context)
31
- evaluation_details = EvaluationDetails.new(flag_key:, resolution_details:)
32
- #{ "evaluation_details.value" if suffix == :value }
33
- end
34
- RUBY
35
- end
19
+ def fetch_boolean_details ( flag_key :, default_value :, evaluation_context : nil )
20
+ fetch_details ( type : :boolean , flag_key :, default_value :, evaluation_context :)
21
+ end
22
+
23
+ def fetch_boolean_value ( flag_key :, default_value :, evaluation_context : nil )
24
+ fetch_details ( type : :boolean , flag_key :, default_value :, evaluation_context :) . value
25
+ end
26
+
27
+ def fetch_string_details ( flag_key :, default_value :, evaluation_context : nil )
28
+ fetch_details ( type : :string , flag_key :, default_value :, evaluation_context :)
29
+ end
30
+
31
+ def fetch_string_value ( flag_key :, default_value :, evaluation_context : nil )
32
+ fetch_details ( type : :string , flag_key :, default_value :, evaluation_context :) . value
33
+ end
34
+
35
+ def fetch_number_details ( flag_key :, default_value :, evaluation_context : nil )
36
+ fetch_details ( type : :number , flag_key :, default_value :, evaluation_context :)
37
+ end
38
+
39
+ def fetch_number_value ( flag_key :, default_value :, evaluation_context : nil )
40
+ fetch_details ( type : :number , flag_key :, default_value :, evaluation_context :) . value
41
+ end
42
+
43
+ def fetch_integer_details ( flag_key :, default_value :, evaluation_context : nil )
44
+ fetch_details ( type : :integer , flag_key :, default_value :, evaluation_context :)
45
+ end
46
+
47
+ def fetch_integer_value ( flag_key :, default_value :, evaluation_context : nil )
48
+ fetch_details ( type : :integer , flag_key :, default_value :, evaluation_context :) . value
49
+ end
50
+
51
+ def fetch_float_details ( flag_key :, default_value :, evaluation_context : nil )
52
+ fetch_details ( type : :float , flag_key :, default_value :, evaluation_context :)
53
+ end
54
+
55
+ def fetch_float_value ( flag_key :, default_value :, evaluation_context : nil )
56
+ fetch_details ( type : :float , flag_key :, default_value :, evaluation_context :) . value
57
+ end
58
+
59
+ def fetch_object_details ( flag_key :, default_value :, evaluation_context : nil )
60
+ fetch_details ( type : :object , flag_key :, default_value :, evaluation_context :)
61
+ end
62
+
63
+ def fetch_object_value ( flag_key :, default_value :, evaluation_context : nil )
64
+ fetch_details ( type : :object , flag_key :, default_value :, evaluation_context :) . value
65
+ end
66
+
67
+ private
68
+
69
+ def fetch_details ( type :, flag_key :, default_value :, evaluation_context : nil )
70
+ built_context = EvaluationContextBuilder . new . call ( api_context : OpenFeature ::SDK . evaluation_context , client_context : self . evaluation_context , invocation_context : evaluation_context )
71
+
72
+ EvaluationDetails . new (
73
+ flag_key :,
74
+ resolution_details : @provider . send ( :"fetch_#{ type } _value" , flag_key :, default_value :, evaluation_context : built_context )
75
+ )
36
76
end
37
77
end
38
78
end
0 commit comments