Class: Featurevisor::OpenFeatureProvider
- Inherits:
-
Object
- Object
- Featurevisor::OpenFeatureProvider
- Defined in:
- lib/featurevisor/openfeature_provider.rb
Constant Summary collapse
- Provider =
OpenFeature::SDK::Provider
Instance Attribute Summary collapse
-
#featurevisor ⇒ Object
readonly
Returns the value of attribute featurevisor.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
- #fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
- #fetch_float_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
- #fetch_integer_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
- #fetch_number_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
- #fetch_object_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
- #fetch_string_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
- #hooks ⇒ Object
- #init(_evaluation_context = nil) ⇒ Object
-
#initialize(options = {}, featurevisor: nil, targeting_key_field: "userId", key_separator: ":", variation_key: "variation", global_variable_prefix: "variable", on_track: nil, **featurevisor_options) ⇒ OpenFeatureProvider
constructor
A new instance of OpenFeatureProvider.
- #shutdown ⇒ Object
- #track(tracking_event_name:, evaluation_context: nil, tracking_event_details: nil) ⇒ Object
Constructor Details
#initialize(options = {}, featurevisor: nil, targeting_key_field: "userId", key_separator: ":", variation_key: "variation", global_variable_prefix: "variable", on_track: nil, **featurevisor_options) ⇒ OpenFeatureProvider
Returns a new instance of OpenFeatureProvider.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/featurevisor/openfeature_provider.rb', line 14 def initialize( = {}, featurevisor: nil, targeting_key_field: "userId", key_separator: ":", variation_key: "variation", global_variable_prefix: "variable", on_track: nil, **) raise ArgumentError, "options must be a Hash" unless .is_a?(Hash) @metadata = Provider::ProviderMetadata.new(name: "Featurevisor").freeze @targeting_key_field = targeting_key_field.empty? ? "userId" : targeting_key_field @key_separator = key_separator.empty? ? ":" : key_separator @variation_key = variation_key.empty? ? "variation" : variation_key @global_variable_prefix = global_variable_prefix.empty? ? "variable" : global_variable_prefix raise ArgumentError, "global_variable_prefix cannot contain key_separator" if @global_variable_prefix.include?(@key_separator) @on_track = on_track @datafile_error = nil @shutdown = false @owns_featurevisor = featurevisor.nil? if featurevisor @featurevisor = featurevisor else = .merge() initial_datafile = .delete(:datafile) @featurevisor = Featurevisor.create_featurevisor() end @error_unsubscribe = @featurevisor.on("error", lambda do |event| diagnostic = event[:diagnostic] @datafile_error = diagnostic[:message] if diagnostic&.dig(:code) == "invalid_datafile" end) @datafile_unsubscribe = @featurevisor.on("datafile_set", ->(*) { @datafile_error = nil }) @featurevisor.set_datafile(initial_datafile, true) if @owns_featurevisor && initial_datafile end |
Instance Attribute Details
#featurevisor ⇒ Object (readonly)
Returns the value of attribute featurevisor.
12 13 14 |
# File 'lib/featurevisor/openfeature_provider.rb', line 12 def featurevisor @featurevisor end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
12 13 14 |
# File 'lib/featurevisor/openfeature_provider.rb', line 12 def @metadata end |
Instance Method Details
#fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
57 58 59 |
# File 'lib/featurevisor/openfeature_provider.rb', line 57 def fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil) resolve(flag_key, default_value, evaluation_context, :boolean) end |
#fetch_float_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
73 74 75 |
# File 'lib/featurevisor/openfeature_provider.rb', line 73 def fetch_float_value(flag_key:, default_value:, evaluation_context: nil) resolve(flag_key, default_value, evaluation_context, :float) end |
#fetch_integer_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
69 70 71 |
# File 'lib/featurevisor/openfeature_provider.rb', line 69 def fetch_integer_value(flag_key:, default_value:, evaluation_context: nil) resolve(flag_key, default_value, evaluation_context, :integer) end |
#fetch_number_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
65 66 67 |
# File 'lib/featurevisor/openfeature_provider.rb', line 65 def fetch_number_value(flag_key:, default_value:, evaluation_context: nil) resolve(flag_key, default_value, evaluation_context, :number) end |
#fetch_object_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
77 78 79 |
# File 'lib/featurevisor/openfeature_provider.rb', line 77 def fetch_object_value(flag_key:, default_value:, evaluation_context: nil) resolve(flag_key, default_value, evaluation_context, :object) end |
#fetch_string_value(flag_key:, default_value:, evaluation_context: nil) ⇒ Object
61 62 63 |
# File 'lib/featurevisor/openfeature_provider.rb', line 61 def fetch_string_value(flag_key:, default_value:, evaluation_context: nil) resolve(flag_key, default_value, evaluation_context, :string) end |
#hooks ⇒ Object
51 |
# File 'lib/featurevisor/openfeature_provider.rb', line 51 def hooks = [] |
#init(_evaluation_context = nil) ⇒ Object
42 |
# File 'lib/featurevisor/openfeature_provider.rb', line 42 def init(_evaluation_context = nil); end |
#shutdown ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/featurevisor/openfeature_provider.rb', line 43 def shutdown return if @shutdown @shutdown = true @error_unsubscribe&.call @datafile_unsubscribe&.call featurevisor.close if @owns_featurevisor end |
#track(tracking_event_name:, evaluation_context: nil, tracking_event_details: nil) ⇒ Object
53 54 55 |
# File 'lib/featurevisor/openfeature_provider.rb', line 53 def track(tracking_event_name:, evaluation_context: nil, tracking_event_details: nil) @on_track&.call(tracking_event_name, evaluation_context, tracking_event_details) end |