Class: FeatureHub::Sdk::FeatureHubConfig
- Inherits:
-
Object
- Object
- FeatureHub::Sdk::FeatureHubConfig
- Defined in:
- lib/feature_hub/sdk/feature_hub_config.rb
Overview
central dispatch class for FeatureHub SDK
Instance Attribute Summary collapse
-
#api_keys ⇒ Object
readonly
Returns the value of attribute api_keys.
-
#client_evaluated ⇒ Object
readonly
Returns the value of attribute client_evaluated.
-
#edge_url ⇒ Object
readonly
Returns the value of attribute edge_url.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #close ⇒ Object
-
#edge_service_provider(edge_provider = nil) ⇒ Object
rubocop:enable Naming/AccessorMethodName.
- #force_new_edge_service ⇒ Object
-
#get_or_create_edge_service ⇒ Object
rubocop:disable Naming/AccessorMethodName.
- #init ⇒ Object
-
#initialize(edge_url, api_keys, repository = nil, edge_provider = nil, logger = nil) ⇒ FeatureHubConfig
constructor
A new instance of FeatureHubConfig.
- #new_context ⇒ Object
- #repository(repo = nil) ⇒ Object
- #use_polling_edge_service(interval = ENV.fetch("FEATUREHUB_POLL_INTERVAL", "30").to_i) ⇒ Object
Constructor Details
#initialize(edge_url, api_keys, repository = nil, edge_provider = nil, logger = nil) ⇒ FeatureHubConfig
Returns a new instance of FeatureHubConfig.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/feature_hub/sdk/feature_hub_config.rb', line 24 def initialize(edge_url, api_keys, repository = nil, edge_provider = nil, logger = nil) raise "edge_url is not set to a valid string" if edge_url.nil? || edge_url.strip.empty? raise "api_keys must be an array of API keys" if api_keys.nil? || !api_keys.is_a?(Array) || api_keys.empty? detect_client_evaluated(api_keys) @edge_url = parse_edge_url(edge_url) @api_keys = api_keys @repository = repository || FeatureHub::Sdk::FeatureHubRepository.new @edge_service_provider = edge_provider || method(:create_default_provider) @logger = logger || FeatureHub::Sdk.default_logger end |
Instance Attribute Details
#api_keys ⇒ Object (readonly)
Returns the value of attribute api_keys.
22 23 24 |
# File 'lib/feature_hub/sdk/feature_hub_config.rb', line 22 def api_keys @api_keys end |
#client_evaluated ⇒ Object (readonly)
Returns the value of attribute client_evaluated.
22 23 24 |
# File 'lib/feature_hub/sdk/feature_hub_config.rb', line 22 def client_evaluated @client_evaluated end |
#edge_url ⇒ Object (readonly)
Returns the value of attribute edge_url.
22 23 24 |
# File 'lib/feature_hub/sdk/feature_hub_config.rb', line 22 def edge_url @edge_url end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
22 23 24 |
# File 'lib/feature_hub/sdk/feature_hub_config.rb', line 22 def logger @logger end |
Instance Method Details
#close ⇒ Object
92 93 94 95 96 97 |
# File 'lib/feature_hub/sdk/feature_hub_config.rb', line 92 def close return if @edge_service.nil? @edge_service.close @edge_service = nil end |
#edge_service_provider(edge_provider = nil) ⇒ Object
rubocop:enable Naming/AccessorMethodName
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/feature_hub/sdk/feature_hub_config.rb', line 64 def edge_service_provider(edge_provider = nil) return @edge_service_provider if edge_provider.nil? @edge_service_provider = edge_provider if @edge_service @edge_service&.close @edge_service = nil end edge_provider end |
#force_new_edge_service ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/feature_hub/sdk/feature_hub_config.rb', line 47 def force_new_edge_service if @edge_service @edge_service&.close @edge_service = nil end get_or_create_edge_service end |
#get_or_create_edge_service ⇒ Object
rubocop:disable Naming/AccessorMethodName
57 58 59 60 61 |
# File 'lib/feature_hub/sdk/feature_hub_config.rb', line 57 def get_or_create_edge_service @edge_service = create_edge_service if @edge_service.nil? @edge_service end |
#init ⇒ Object
42 43 44 45 |
# File 'lib/feature_hub/sdk/feature_hub_config.rb', line 42 def init get_or_create_edge_service.poll self end |
#new_context ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/feature_hub/sdk/feature_hub_config.rb', line 82 def new_context get_or_create_edge_service if @client_evaluated ClientEvalFeatureContext.new(@repository, @edge_service) else ServerEvalFeatureContext.new(@repository, @edge_service) end end |
#repository(repo = nil) ⇒ Object
38 39 40 |
# File 'lib/feature_hub/sdk/feature_hub_config.rb', line 38 def repository(repo = nil) @repository = repo || @repository end |
#use_polling_edge_service(interval = ENV.fetch("FEATUREHUB_POLL_INTERVAL", "30").to_i) ⇒ Object
77 78 79 80 |
# File 'lib/feature_hub/sdk/feature_hub_config.rb', line 77 def use_polling_edge_service(interval = ENV.fetch("FEATUREHUB_POLL_INTERVAL", "30").to_i) @interval = interval @edge_service_provider = method(:create_polling_edge_provider) end |