29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/featbit/openfeature/details_converter.rb', line 29
def self.convert(detail, type, default_value)
unless detail.success?
return error(default_value, ERROR_CODES.fetch(detail.error_kind, API::ErrorCode::GENERAL),
detail.error_message || detail.reason)
end
value = detail.value
unless TYPES.fetch(type).any? { |klass| value.is_a?(klass) }
return error(default_value, API::ErrorCode::TYPE_MISMATCH, "Flag value is not of type #{type}")
end
value = value.to_i if type == :integer
value = value.to_f if type == :float
metadata = { "featbit.reason" => detail.reason, "featbit.in_experiment" => detail.send_to_experiment == true }
metadata["featbit.flag_name"] = detail.flag_name unless detail.flag_name.nil?
API::ResolutionDetails.new(value: value, reason: REASONS.fetch(detail.reason, API::Reason::UNKNOWN),
variant: detail.variation_id&.to_s, flag_metadata: metadata)
end
|