Class: Flipper::Cloud::Configuration
- Inherits:
-
Object
- Object
- Flipper::Cloud::Configuration
- Defined in:
- lib/flipper/cloud/configuration.rb
Constant Summary collapse
- VALID_SYNC_METHODS =
The set of valid ways that syncing can happpen.
Set[ :poll, :webhook, ].freeze
- DEFAULT_URL =
"https://www.flippercloud.io/adapter".freeze
Instance Attribute Summary collapse
-
#debug_output ⇒ Object
Public: IO stream to send debug output too.
-
#instrumenter ⇒ Object
Public: Instrumenter to use for the Flipper instance returned by Flipper::Cloud.new (default: Flipper::Instrumenters::Noop).
-
#local_adapter ⇒ Object
Public: Local adapter that all reads should go to in order to ensure latency is low and resiliency is high.
-
#logger ⇒ Object
Public: The logger to use for debugging inner workings.
-
#logging_enabled ⇒ Object
Public: Should the logger log or not (default: true).
-
#open_timeout ⇒ Object
Public: net/http open timeout for all http requests (default: 5).
-
#read_timeout ⇒ Object
Public: net/http read timeout for all http requests (default: 5).
-
#sync_interval ⇒ Object
Public: The Integer or Float number of seconds between attempts to bring the local in sync with cloud (default: 10).
-
#sync_secret ⇒ Object
Public: The secret used to verify if syncs in the middleware should occur or not.
-
#telemetry ⇒ Object
Public: The telemetry instance to use for tracking feature usage.
-
#telemetry_enabled ⇒ Object
Public: Should telemetry be enabled or not (default: false).
-
#token ⇒ Object
Public: The token corresponding to an environment on flippercloud.io.
-
#url ⇒ Object
Public: The url for http adapter.
-
#write_timeout ⇒ Object
Public: net/http write timeout for all http requests (default: 5).
Instance Method Summary collapse
-
#adapter(&block) ⇒ Object
Public: Read or customize the http adapter.
-
#http_client ⇒ Object
Internal: The http client used by the http adapter.
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
-
#log(message, level: :debug) ⇒ Object
Internal: Logs message if logging is enabled.
-
#sync ⇒ Object
Public: Force a sync.
-
#sync_method ⇒ Object
Public: The method that will be used to synchronize local adapter with cloud.
Constructor Details
#initialize(options = {}) ⇒ Configuration
Returns a new instance of Configuration.
85 86 87 88 89 90 91 92 |
# File 'lib/flipper/cloud/configuration.rb', line 85 def initialize( = {}) setup_auth setup_log setup_http setup_sync setup_adapter setup_telemetry end |
Instance Attribute Details
#debug_output ⇒ Object
Public: IO stream to send debug output too. Off by default.
# for example, this would send all http request information to STDOUT
configuration = Flipper::Cloud::Configuration.new
configuration.debug_output = STDOUT
46 47 48 |
# File 'lib/flipper/cloud/configuration.rb', line 46 def debug_output @debug_output end |
#instrumenter ⇒ Object
Public: Instrumenter to use for the Flipper instance returned by
Flipper::Cloud.new (default: Flipper::Instrumenters::Noop).
# for example, to use active support notifications you could do:
configuration = Flipper::Cloud::Configuration.new
configuration.instrumenter = ActiveSupport::Notifications
54 55 56 |
# File 'lib/flipper/cloud/configuration.rb', line 54 def instrumenter @instrumenter end |
#local_adapter ⇒ Object
Public: Local adapter that all reads should go to in order to ensure latency is low and resiliency is high. This adapter is automatically kept in sync with cloud.
# for example, to use active record you could do:
configuration = Flipper::Cloud::Configuration.new
configuration.local_adapter = Flipper::Adapters::ActiveRecord.new
63 64 65 |
# File 'lib/flipper/cloud/configuration.rb', line 63 def local_adapter @local_adapter end |
#logger ⇒ Object
Public: The logger to use for debugging inner workings.
74 75 76 |
# File 'lib/flipper/cloud/configuration.rb', line 74 def logger @logger end |
#logging_enabled ⇒ Object
Public: Should the logger log or not (default: true).
77 78 79 |
# File 'lib/flipper/cloud/configuration.rb', line 77 def logging_enabled @logging_enabled end |
#open_timeout ⇒ Object
Public: net/http open timeout for all http requests (default: 5).
36 37 38 |
# File 'lib/flipper/cloud/configuration.rb', line 36 def open_timeout @open_timeout end |
#read_timeout ⇒ Object
Public: net/http read timeout for all http requests (default: 5).
33 34 35 |
# File 'lib/flipper/cloud/configuration.rb', line 33 def read_timeout @read_timeout end |
#sync_interval ⇒ Object
Public: The Integer or Float number of seconds between attempts to bring the local in sync with cloud (default: 10).
67 68 69 |
# File 'lib/flipper/cloud/configuration.rb', line 67 def sync_interval @sync_interval end |
#sync_secret ⇒ Object
Public: The secret used to verify if syncs in the middleware should occur or not.
71 72 73 |
# File 'lib/flipper/cloud/configuration.rb', line 71 def sync_secret @sync_secret end |
#telemetry ⇒ Object
Public: The telemetry instance to use for tracking feature usage.
80 81 82 |
# File 'lib/flipper/cloud/configuration.rb', line 80 def telemetry @telemetry end |
#telemetry_enabled ⇒ Object
Public: Should telemetry be enabled or not (default: false).
83 84 85 |
# File 'lib/flipper/cloud/configuration.rb', line 83 def telemetry_enabled @telemetry_enabled end |
#token ⇒ Object
Public: The token corresponding to an environment on flippercloud.io.
25 26 27 |
# File 'lib/flipper/cloud/configuration.rb', line 25 def token @token end |
#url ⇒ Object
Public: The url for http adapter. Really should only be customized for
development work if you are me and you are not me. Feel free to
forget you ever saw this.
30 31 32 |
# File 'lib/flipper/cloud/configuration.rb', line 30 def url @url end |
#write_timeout ⇒ Object
Public: net/http write timeout for all http requests (default: 5).
39 40 41 |
# File 'lib/flipper/cloud/configuration.rb', line 39 def write_timeout @write_timeout end |
Instance Method Details
#adapter(&block) ⇒ Object
Public: Read or customize the http adapter. Calling without a block will perform a read. Calling with a block yields the cloud adapter for customization.
# for example, to instrument the http calls, you can wrap the http
# adapter with the intsrumented adapter
configuration = Flipper::Cloud::Configuration.new
configuration.adapter do |adapter|
Flipper::Adapters::Instrumented.new(adapter)
end
105 106 107 108 109 110 111 |
# File 'lib/flipper/cloud/configuration.rb', line 105 def adapter(&block) if block_given? @adapter_block = block else @adapter_block.call app_adapter end end |
#http_client ⇒ Object
Internal: The http client used by the http adapter. Exposed so we can use the same client for posting telemetry.
128 129 130 |
# File 'lib/flipper/cloud/configuration.rb', line 128 def http_client http_adapter.client end |
#log(message, level: :debug) ⇒ Object
Internal: Logs message if logging is enabled.
133 134 135 136 |
# File 'lib/flipper/cloud/configuration.rb', line 133 def log(, level: :debug) return unless logging_enabled logger.send(level, "name=flipper_cloud #{}") end |
#sync ⇒ Object
Public: Force a sync.
114 115 116 117 118 |
# File 'lib/flipper/cloud/configuration.rb', line 114 def sync Flipper::Adapters::Sync::Synchronizer.new(local_adapter, http_adapter, { instrumenter: instrumenter, }).call end |
#sync_method ⇒ Object
Public: The method that will be used to synchronize local adapter with cloud. (default: :poll, will be :webhook if sync_secret is set).
122 123 124 |
# File 'lib/flipper/cloud/configuration.rb', line 122 def sync_method sync_secret ? :webhook : :poll end |