Class: OpenFeatureSorbet::Client

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/open_feature_sorbet/client.rb

Overview

Used during runtime for evaluating features.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider:, name: nil, evaluation_context: nil, hooks: []) ⇒ Client

Returns a new instance of Client.



26
27
28
29
30
31
# File 'lib/open_feature_sorbet/client.rb', line 26

def initialize(provider:, name: nil, evaluation_context: nil, hooks: [])
  @provider = provider
  @client_metadata = T.let(ClientMetadata.new(name: name), ClientMetadata)
  @evaluation_context = evaluation_context
  @hooks = hooks
end

Instance Attribute Details

#client_metadataObject (readonly)

Returns the value of attribute client_metadata.



10
11
12
# File 'lib/open_feature_sorbet/client.rb', line 10

def 
  @client_metadata
end

#evaluation_contextObject

Returns the value of attribute evaluation_context.



13
14
15
# File 'lib/open_feature_sorbet/client.rb', line 13

def evaluation_context
  @evaluation_context
end

#hooksObject (readonly)

Returns the value of attribute hooks.



16
17
18
# File 'lib/open_feature_sorbet/client.rb', line 16

def hooks
  @hooks
end

Instance Method Details

#add_hooks(hooks) ⇒ Object



34
35
36
# File 'lib/open_feature_sorbet/client.rb', line 34

def add_hooks(hooks)
  @hooks.concat(Array(hooks))
end

#fetch_boolean_details(flag_key:, default_value:, context: nil, options: nil) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/open_feature_sorbet/client.rb', line 64

def fetch_boolean_details(flag_key:, default_value:, context: nil, options: nil) # rubocop:disable Lint/UnusedMethodArgument
  details = provider.resolve_boolean_value(
    flag_key: flag_key,
    default_value: default_value,
    context: build_context(context)
  )

  EvaluationDetails.from_resolution_details(details, flag_key: flag_key)
rescue StandardError => e
  EvaluationDetails.from_error(e.message, flag_key: flag_key, default_value: default_value)
end

#fetch_boolean_value(flag_key:, default_value:, context: nil, options: nil) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/open_feature_sorbet/client.rb', line 46

def fetch_boolean_value(flag_key:, default_value:, context: nil, options: nil)
  evaluated_context = build_context_with_before_hooks(flag_key: flag_key, default_value: default_value,
                                                      invocation_context: context, options: options,
                                                      flag_type: "Boolean")
  provider.resolve_boolean_value(flag_key: flag_key, default_value: default_value, context: evaluated_context)
          .value
rescue StandardError
  default_value
end

#fetch_float_value(flag_key:, default_value:, context: nil, options: nil) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
# File 'lib/open_feature_sorbet/client.rb', line 182

def fetch_float_value(flag_key:, default_value:, context: nil, options: nil)
  evaluated_context = build_context_with_before_hooks(flag_key: flag_key, default_value: default_value,
                                                      invocation_context: context, options: options,
                                                      flag_type: "Float")
  provider
    .resolve_number_value(flag_key: flag_key, default_value: default_value, context: evaluated_context)
    .value
    .to_f
rescue StandardError
  default_value
end

#fetch_integer_value(flag_key:, default_value:, context: nil, options: nil) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
# File 'lib/open_feature_sorbet/client.rb', line 162

def fetch_integer_value(flag_key:, default_value:, context: nil, options: nil)
  evaluated_context = build_context_with_before_hooks(flag_key: flag_key, default_value: default_value,
                                                      invocation_context: context, options: options,
                                                      flag_type: "Integer")
  provider
    .resolve_number_value(flag_key: flag_key, default_value: default_value, context: evaluated_context)
    .value
    .to_i
rescue StandardError
  default_value
end

#fetch_number_details(flag_key:, default_value:, context: nil, options: nil) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



142
143
144
145
146
147
148
149
150
151
152
# File 'lib/open_feature_sorbet/client.rb', line 142

def fetch_number_details(flag_key:, default_value:, context: nil, options: nil) # rubocop:disable Lint/UnusedMethodArgument
  details = provider.resolve_number_value(
    flag_key: flag_key,
    default_value: default_value,
    context: build_context(context)
  )

  EvaluationDetails.from_resolution_details(details, flag_key: flag_key)
rescue StandardError => e
  EvaluationDetails.from_error(e.message, flag_key: flag_key, default_value: default_value)
end

#fetch_number_value(flag_key:, default_value:, context: nil, options: nil) ⇒ Object



123
124
125
126
127
128
129
130
131
132
# File 'lib/open_feature_sorbet/client.rb', line 123

def fetch_number_value(flag_key:, default_value:, context: nil, options: nil)
  evaluated_context = build_context_with_before_hooks(flag_key: flag_key, default_value: default_value,
                                                      invocation_context: context, options: options,
                                                      flag_type: "Number")
  provider
    .resolve_number_value(flag_key: flag_key, default_value: default_value, context: evaluated_context)
    .value
rescue StandardError
  default_value
end

#fetch_string_details(flag_key:, default_value:, context: nil, options: nil) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/open_feature_sorbet/client.rb', line 103

def fetch_string_details(flag_key:, default_value:, context: nil, options: nil) # rubocop:disable Lint/UnusedMethodArgument
  details = provider.resolve_string_value(
    flag_key: flag_key,
    default_value: default_value,
    context: build_context(context)
  )

  EvaluationDetails.from_resolution_details(details, flag_key: flag_key)
rescue StandardError => e
  EvaluationDetails.from_error(e.message, flag_key: flag_key, default_value: default_value)
end

#fetch_string_value(flag_key:, default_value:, context: nil, options: nil) ⇒ Object



84
85
86
87
88
89
90
91
92
93
# File 'lib/open_feature_sorbet/client.rb', line 84

def fetch_string_value(flag_key:, default_value:, context: nil, options: nil)
  evaluated_context = build_context_with_before_hooks(flag_key: flag_key, default_value: default_value,
                                                      invocation_context: context, options: options,
                                                      flag_type: "String")
  provider
    .resolve_string_value(flag_key: flag_key, default_value: default_value, context: evaluated_context)
    .value
rescue StandardError
  default_value
end

#fetch_structure_details(flag_key:, default_value:, context: nil, options: nil) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



221
222
223
224
225
226
227
228
229
230
231
# File 'lib/open_feature_sorbet/client.rb', line 221

def fetch_structure_details(flag_key:, default_value:, context: nil, options: nil) # rubocop:disable Lint/UnusedMethodArgument
  details = provider.resolve_structure_value(
    flag_key: flag_key,
    default_value: default_value,
    context: build_context(context)
  )

  EvaluationDetails.from_resolution_details(details, flag_key: flag_key)
rescue StandardError => e
  EvaluationDetails.from_error(e.message, flag_key: flag_key, default_value: default_value)
end

#fetch_structure_value(flag_key:, default_value:, context: nil, options: nil) ⇒ Object



202
203
204
205
206
207
208
209
210
211
# File 'lib/open_feature_sorbet/client.rb', line 202

def fetch_structure_value(flag_key:, default_value:, context: nil, options: nil)
  evaluated_context = build_context_with_before_hooks(flag_key: flag_key, default_value: default_value,
                                                      invocation_context: context, options: options,
                                                      flag_type: "Structure")
  provider
    .resolve_structure_value(flag_key: flag_key, default_value: default_value, context: evaluated_context)
    .value
rescue StandardError
  default_value
end