Class: OpenFeature::SDK::Contrib::Providers::FileProvider
- Inherits:
-
Object
- Object
- OpenFeature::SDK::Contrib::Providers::FileProvider
- Includes:
- Common
- Defined in:
- lib/open_feature/sdk/contrib/providers/file_provider.rb
Overview
Read feature flags from a file.
To use FileProvider
, it can be set during the configuration of the SDK
OpenFeature::SDK.configure do |config|
config.provider = OpenFeature::SDK::Contrib::Providers::FileProvider.new(source: "/path/to/file")
end
Within the FileProvider
, the following methods exist
-
fetch_boolean_value
- Retrieve feature flag boolean value from the file -
fetch_string_value
- Retrieve feature flag string value from the file -
fetch_number_value
- Retrieve feature flag number value from the file -
fetch_object_value
- Retrieve feature flag object value from the file
Constant Summary collapse
- NAME =
"File Provider"
Instance Attribute Summary
Attributes included from Common
#cache_duration, #custom_parser, #deep_keys, #extra_options, #format, #metadata, #source
Instance Method Summary collapse
Methods included from Common
#expire_cache!, #fetch_boolean_value, #fetch_float_value, #fetch_number_value, #fetch_object_value, #fetch_raw_key, #fetch_string_value, #initialize, #read_all_values_with_cache
Instance Method Details
#read_and_parse_flags ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/open_feature/sdk/contrib/providers/file_provider.rb', line 32 def read_and_parse_flags file_contents = begin ERB.new(File.read(File.(source))).result rescue Errno::ENOENT @flag_contents = {} end return @flag_contents if @flag_contents return custom_parser.call(file_contents) if custom_parser @flag_contents = if format == :yaml YAML.safe_load(file_contents) else JSON.parse(file_contents) end @flag_contents end |