|
4 | 4 | require 'ldclient-rb/config' |
5 | 5 | require 'ldclient-rb/impl/data_system/polling' |
6 | 6 | require 'ldclient-rb/impl/data_system/streaming' |
| 7 | +require 'ldclient-rb/data_system/config_builder' |
| 8 | +require 'ldclient-rb/data_system/polling_data_source_builder' |
| 9 | +require 'ldclient-rb/data_system/streaming_data_source_builder' |
7 | 10 |
|
8 | 11 | module LaunchDarkly |
9 | 12 | # |
10 | 13 | # Configuration for LaunchDarkly's data acquisition strategy. |
11 | 14 | # |
12 | | - # This module provides factory methods for creating data system configurations. |
| 15 | + # This module provides factory methods for creating data system configurations, |
| 16 | + # as well as builder classes for constructing individual data sources (polling |
| 17 | + # and streaming). |
| 18 | + # |
| 19 | + # == Quick Start |
| 20 | + # |
| 21 | + # For most users, the predefined strategies are sufficient: |
| 22 | + # |
| 23 | + # # Use the default strategy (recommended) |
| 24 | + # config = LaunchDarkly::Config.new( |
| 25 | + # data_system: LaunchDarkly::DataSystem.default |
| 26 | + # ) |
| 27 | + # |
| 28 | + # # Use streaming only |
| 29 | + # config = LaunchDarkly::Config.new( |
| 30 | + # data_system: LaunchDarkly::DataSystem.streaming |
| 31 | + # ) |
| 32 | + # |
| 33 | + # # Use polling only |
| 34 | + # config = LaunchDarkly::Config.new( |
| 35 | + # data_system: LaunchDarkly::DataSystem.polling |
| 36 | + # ) |
| 37 | + # |
| 38 | + # == Custom Configurations |
| 39 | + # |
| 40 | + # For advanced use cases, you can build custom configurations using the |
| 41 | + # data source builders: |
| 42 | + # |
| 43 | + # polling = LaunchDarkly::DataSystem.polling_ds_builder |
| 44 | + # .poll_interval(60) |
| 45 | + # .base_uri("https://custom-polling.example.com") |
| 46 | + # |
| 47 | + # streaming = LaunchDarkly::DataSystem.streaming_ds_builder |
| 48 | + # .initial_reconnect_delay(2) |
| 49 | + # .base_uri("https://custom-streaming.example.com") |
| 50 | + # |
| 51 | + # data_system = LaunchDarkly::DataSystem.custom |
| 52 | + # .initializers([polling]) |
| 53 | + # .synchronizers([streaming, polling]) |
| 54 | + # |
| 55 | + # config = LaunchDarkly::Config.new(data_system: data_system) |
13 | 56 | # |
14 | 57 | module DataSystem |
15 | | - # |
16 | | - # Builder for the data system configuration. |
17 | | - # |
18 | | - class ConfigBuilder |
19 | | - def initialize |
20 | | - @initializers = nil |
21 | | - @synchronizers = nil |
22 | | - @fdv1_fallback_synchronizer = nil |
23 | | - @data_store_mode = LaunchDarkly::Interfaces::DataSystem::DataStoreMode::READ_ONLY |
24 | | - @data_store = nil |
25 | | - end |
26 | | - |
27 | | - # |
28 | | - # Sets the initializers for the data system. |
29 | | - # |
30 | | - # @param initializers [Array<#build(String, Config)>] |
31 | | - # Array of builders that respond to build(sdk_key, config) and return an Initializer |
32 | | - # @return [ConfigBuilder] self for chaining |
33 | | - # |
34 | | - def initializers(initializers) |
35 | | - @initializers = initializers |
36 | | - self |
37 | | - end |
38 | | - |
39 | | - # |
40 | | - # Sets the synchronizers for the data system. |
41 | | - # |
42 | | - # @param synchronizers [Array<#build(String, Config)>] |
43 | | - # Array of builders that respond to build(sdk_key, config) and return a Synchronizer |
44 | | - # @return [ConfigBuilder] self for chaining |
45 | | - # |
46 | | - def synchronizers(synchronizers) |
47 | | - @synchronizers = synchronizers |
48 | | - self |
49 | | - end |
50 | | - |
51 | | - # |
52 | | - # Configures the SDK with a fallback synchronizer that is compatible with |
53 | | - # the Flag Delivery v1 API. |
54 | | - # |
55 | | - # @param fallback [#build(String, Config)] Builder that responds to build(sdk_key, config) and returns the fallback Synchronizer |
56 | | - # @return [ConfigBuilder] self for chaining |
57 | | - # |
58 | | - def fdv1_compatible_synchronizer(fallback) |
59 | | - @fdv1_fallback_synchronizer = fallback |
60 | | - self |
61 | | - end |
62 | | - |
63 | | - # |
64 | | - # Sets the data store configuration for the data system. |
65 | | - # |
66 | | - # @param data_store [LaunchDarkly::Interfaces::FeatureStore] The data store |
67 | | - # @param store_mode [Symbol] The store mode |
68 | | - # @return [ConfigBuilder] self for chaining |
69 | | - # |
70 | | - def data_store(data_store, store_mode) |
71 | | - @data_store = data_store |
72 | | - @data_store_mode = store_mode |
73 | | - self |
74 | | - end |
75 | | - |
76 | | - # |
77 | | - # Builds the data system configuration. |
78 | | - # |
79 | | - # @return [DataSystemConfig] |
80 | | - # |
81 | | - def build |
82 | | - DataSystemConfig.new( |
83 | | - initializers: @initializers, |
84 | | - synchronizers: @synchronizers, |
85 | | - data_store_mode: @data_store_mode, |
86 | | - data_store: @data_store, |
87 | | - fdv1_fallback_synchronizer: @fdv1_fallback_synchronizer |
88 | | - ) |
89 | | - end |
90 | | - end |
91 | | - |
92 | 58 | # |
93 | 59 | # Returns a builder for creating a polling data source. |
94 | 60 | # This is a building block that can be used with {ConfigBuilder#initializers} |
95 | 61 | # or {ConfigBuilder#synchronizers} to create custom data system configurations. |
96 | 62 | # |
97 | | - # @return [LaunchDarkly::Impl::DataSystem::PollingDataSourceBuilder] |
| 63 | + # @return [PollingDataSourceBuilder] |
98 | 64 | # |
99 | 65 | def self.polling_ds_builder |
100 | | - LaunchDarkly::Impl::DataSystem::PollingDataSourceBuilder.new |
| 66 | + PollingDataSourceBuilder.new |
101 | 67 | end |
102 | 68 |
|
103 | 69 | # |
104 | 70 | # Returns a builder for creating an FDv1 fallback polling data source. |
105 | 71 | # This is a building block that can be used with {ConfigBuilder#fdv1_compatible_synchronizer} |
106 | 72 | # to provide FDv1 compatibility in custom data system configurations. |
107 | 73 | # |
108 | | - # @return [LaunchDarkly::Impl::DataSystem::FDv1PollingDataSourceBuilder] |
| 74 | + # @return [FDv1PollingDataSourceBuilder] |
109 | 75 | # |
110 | 76 | def self.fdv1_fallback_ds_builder |
111 | | - LaunchDarkly::Impl::DataSystem::FDv1PollingDataSourceBuilder.new |
| 77 | + FDv1PollingDataSourceBuilder.new |
112 | 78 | end |
113 | 79 |
|
114 | 80 | # |
115 | 81 | # Returns a builder for creating a streaming data source. |
116 | 82 | # This is a building block that can be used with {ConfigBuilder#synchronizers} |
117 | 83 | # to create custom data system configurations. |
118 | 84 | # |
119 | | - # @return [LaunchDarkly::Impl::DataSystem::StreamingDataSourceBuilder] |
| 85 | + # @return [StreamingDataSourceBuilder] |
120 | 86 | # |
121 | 87 | def self.streaming_ds_builder |
122 | | - LaunchDarkly::Impl::DataSystem::StreamingDataSourceBuilder.new |
| 88 | + StreamingDataSourceBuilder.new |
123 | 89 | end |
124 | 90 |
|
125 | 91 | # |
@@ -224,4 +190,3 @@ def self.persistent_store(store) |
224 | 190 | end |
225 | 191 | end |
226 | 192 | end |
227 | | - |
0 commit comments