Class: FeatureHub::Sdk::EnvironmentInterceptor

Inherits:
ValueInterceptor show all
Defined in:
lib/feature_hub/sdk/interceptors.rb

Overview

An example of a value interceptor that uses environment variables

Instance Method Summary collapse

Constructor Details

#initializeEnvironmentInterceptor

Returns a new instance of EnvironmentInterceptor.



33
34
35
36
# File 'lib/feature_hub/sdk/interceptors.rb', line 33

def initialize
  super()
  @enabled = ENV.fetch("FEATUREHUB_OVERRIDE_FEATURES", "false") == "true"
end

Instance Method Details

#intercepted_value(feature_key) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/feature_hub/sdk/interceptors.rb', line 38

def intercepted_value(feature_key)
  if @enabled
    found = ENV.fetch("FEATUREHUB_#{sanitize_feature_name(feature_key.to_s)}", nil)
    return InterceptorValue.new(found) unless found.nil?
  end

  nil
end