Skip to content

Commit d4683ca

Browse files
committed
Add offline mode and handler to config
1 parent 7a6a353 commit d4683ca

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/flagsmith/sdk/config.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ class Config
66
DEFAULT_API_URL = 'https://edge.api.flagsmith.com/api/v1/'
77
OPTIONS = %i[
88
environment_key api_url custom_headers request_timeout_seconds enable_local_evaluation
9-
environment_refresh_interval_seconds retries enable_analytics default_flag_handler logger
9+
environment_refresh_interval_seconds retries enable_analytics default_flag_handler
10+
offline_mode offline_handler logger
1011
].freeze
1112

1213
# Available Configs
@@ -31,8 +32,12 @@ class Config
3132
# API to power flag analytics charts
3233
# +default_flag_handler+ - ruby block which will be used in the case where
3334
# flags cannot be retrieved from the API or
34-
# a non existent feature is requested.
35+
# a non-existent feature is requested.
3536
# The searched feature#name will be passed to the block as an argument.
37+
# +offline_mode+ - if enabled, uses a locally provided file and
38+
# bypasses requests to the api.
39+
# +offline_handler+ - A file object that contains a JSON serialization of
40+
# the entire environment, project, flags, etc.
3641
# +logger+ - Pass your logger, default is Logger.new($stdout)
3742
#
3843
attr_reader(*OPTIONS)
@@ -51,6 +56,10 @@ def enable_analytics?
5156
@enable_analytics
5257
end
5358

59+
def offline_mode?
60+
@offline_mode
61+
end
62+
5463
def environment_flags_url
5564
'flags/'
5665
end
@@ -78,6 +87,8 @@ def build_config(options)
7887
@environment_refresh_interval_seconds = opts.fetch(:environment_refresh_interval_seconds, 60)
7988
@enable_analytics = opts.fetch(:enable_analytics, false)
8089
@default_flag_handler = opts[:default_flag_handler]
90+
@offline_mode = opts.fetch(:offline_mode, false)
91+
@offline_handler = opts[:offline_handler]
8192
@logger = options.fetch(:logger, Logger.new($stdout).tap { |l| l.level = :debug })
8293
end
8394
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength

0 commit comments

Comments
 (0)