Class: OpenFeatureSorbet::EvaluationContext

Inherits:
T::Struct
  • Object
show all
Extended by:
T::Sig
Includes:
T::Struct::ActsAsComparable
Defined in:
lib/open_feature_sorbet/evaluation_context.rb

Overview

Provides ambient information for the purposes of flag evaluation. Currently does not meet specification!

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object



23
24
25
# File 'lib/open_feature_sorbet/evaluation_context.rb', line 23

def method_missing(method_name)
  fields.fetch(method_name.to_s, nil)
end

Instance Method Details

#add_field(key, value) ⇒ Object



28
29
30
31
32
33
# File 'lib/open_feature_sorbet/evaluation_context.rb', line 28

def add_field(key, value)
  EvaluationContext.new(
    targeting_key: targeting_key,
    fields: fields.merge({ key => value })
  )
end

#merge(overriding_context) ⇒ Object



41
42
43
44
45
46
# File 'lib/open_feature_sorbet/evaluation_context.rb', line 41

def merge(overriding_context)
  EvaluationContext.new(
    targeting_key: overriding_context.targeting_key || targeting_key,
    fields: fields.merge(overriding_context.fields)
  )
end

#respond_to_missing?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/open_feature_sorbet/evaluation_context.rb', line 18

def respond_to_missing?(method_name)
  fields.key?(method_name.to_s)
end

#to_hObject



36
37
38
# File 'lib/open_feature_sorbet/evaluation_context.rb', line 36

def to_h
  targeting_key.nil? ? fields : fields.merge("targeting_key" => targeting_key)
end