diff --git a/lib/optimizely/config_manager/http_project_config_manager.rb b/lib/optimizely/config_manager/http_project_config_manager.rb index f6c02840..7eceed76 100644 --- a/lib/optimizely/config_manager/http_project_config_manager.rb +++ b/lib/optimizely/config_manager/http_project_config_manager.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # -# Copyright 2019-2020, Optimizely and contributors +# Copyright 2019-2020, 2022, Optimizely and contributors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ module Optimizely class HTTPProjectConfigManager < ProjectConfigManager # Config manager that polls for the datafile and updated ProjectConfig based on an update interval. - attr_reader :stopped, :optimizely_config + attr_reader :stopped # Initialize config manager. One of sdk_key or url has to be set to be able to use. # @@ -80,8 +80,8 @@ def initialize( @last_modified = nil @skip_json_validation = skip_json_validation @notification_center = notification_center.is_a?(Optimizely::NotificationCenter) ? notification_center : NotificationCenter.new(@logger, @error_handler) + @optimizely_config = nil @config = datafile.nil? ? nil : DatafileProjectConfig.create(datafile, @logger, @error_handler, @skip_json_validation) - @optimizely_config = @config.nil? ? nil : OptimizelyConfig.new(@config).config @mutex = Mutex.new @resource = ConditionVariable.new @async_scheduler = AsyncScheduler.new(method(:fetch_datafile_config), @polling_interval, auto_update, @logger) @@ -140,6 +140,12 @@ def config @config end + def optimizely_config + @optimizely_config = OptimizelyConfig.new(@config).config if @optimizely_config.nil? + + @optimizely_config + end + private def fetch_datafile_config @@ -209,7 +215,9 @@ def set_config(config) end @config = config - @optimizely_config = OptimizelyConfig.new(config).config + + # clearing old optimizely config so that a fresh one is generated on the next api call. + @optimizely_config = nil @notification_center.send_notifications(NotificationCenter::NOTIFICATION_TYPES[:OPTIMIZELY_CONFIG_UPDATE]) diff --git a/lib/optimizely/config_manager/static_project_config_manager.rb b/lib/optimizely/config_manager/static_project_config_manager.rb index 2acff2e8..e5c3600f 100644 --- a/lib/optimizely/config_manager/static_project_config_manager.rb +++ b/lib/optimizely/config_manager/static_project_config_manager.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # -# Copyright 2019-2020, Optimizely and contributors +# Copyright 2019-2020, 2022, Optimizely and contributors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ module Optimizely class StaticProjectConfigManager < ProjectConfigManager # Implementation of ProjectConfigManager interface. - attr_reader :config, :optimizely_config + attr_reader :config def initialize(datafile, logger, error_handler, skip_json_validation) # Looks up and sets datafile and config based on response body. @@ -40,8 +40,13 @@ def initialize(datafile, logger, error_handler, skip_json_validation) error_handler, skip_json_validation ) + @optimizely_config = nil + end + + def optimizely_config + @optimizely_config = OptimizelyConfig.new(@config).config if @optimizely_config.nil? - @optimizely_config = @config.nil? ? nil : OptimizelyConfig.new(@config).config + @optimizely_config end end end