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.
- #instrument(name, payload = {}, &block) ⇒ Object
-
#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.
84 85 86 87 88 89 90 91 |
# File 'lib/flipper/cloud/configuration.rb', line 84 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
45 46 47 |
# File 'lib/flipper/cloud/configuration.rb', line 45 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
53 54 55 |
# File 'lib/flipper/cloud/configuration.rb', line 53 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
62 63 64 |
# File 'lib/flipper/cloud/configuration.rb', line 62 def local_adapter @local_adapter end |
#logger ⇒ Object
Public: The logger to use for debugging inner workings.
73 74 75 |
# File 'lib/flipper/cloud/configuration.rb', line 73 def logger @logger end |
#logging_enabled ⇒ Object
Public: Should the logger log or not (default: true).
76 77 78 |
# File 'lib/flipper/cloud/configuration.rb', line 76 def logging_enabled @logging_enabled end |
#open_timeout ⇒ Object
Public: net/http open timeout for all http requests (default: 5).
35 36 37 |
# File 'lib/flipper/cloud/configuration.rb', line 35 def open_timeout @open_timeout end |
#read_timeout ⇒ Object
Public: net/http read timeout for all http requests (default: 5).
32 33 34 |
# File 'lib/flipper/cloud/configuration.rb', line 32 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).
66 67 68 |
# File 'lib/flipper/cloud/configuration.rb', line 66 def sync_interval @sync_interval end |
#sync_secret ⇒ Object
Public: The secret used to verify if syncs in the middleware should occur or not.
70 71 72 |
# File 'lib/flipper/cloud/configuration.rb', line 70 def sync_secret @sync_secret end |
#telemetry ⇒ Object
Public: The telemetry instance to use for tracking feature usage.
79 80 81 |
# File 'lib/flipper/cloud/configuration.rb', line 79 def telemetry @telemetry end |
#telemetry_enabled ⇒ Object
Public: Should telemetry be enabled or not (default: false).
82 83 84 |
# File 'lib/flipper/cloud/configuration.rb', line 82 def telemetry_enabled @telemetry_enabled end |
#token ⇒ Object
Public: The token corresponding to an environment on flippercloud.io.
24 25 26 |
# File 'lib/flipper/cloud/configuration.rb', line 24 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.
29 30 31 |
# File 'lib/flipper/cloud/configuration.rb', line 29 def url @url end |
#write_timeout ⇒ Object
Public: net/http write timeout for all http requests (default: 5).
38 39 40 |
# File 'lib/flipper/cloud/configuration.rb', line 38 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
104 105 106 107 108 109 110 |
# File 'lib/flipper/cloud/configuration.rb', line 104 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.
127 128 129 |
# File 'lib/flipper/cloud/configuration.rb', line 127 def http_client http_adapter.client end |
#instrument(name, payload = {}, &block) ⇒ Object
137 138 139 |
# File 'lib/flipper/cloud/configuration.rb', line 137 def instrument(name, payload = {}, &block) instrumenter.instrument(name, payload, &block) end |
#log(message, level: :debug) ⇒ Object
Internal: Logs message if logging is enabled.
132 133 134 135 |
# File 'lib/flipper/cloud/configuration.rb', line 132 def log(, level: :debug) return unless logging_enabled logger.send(level, "name=flipper_cloud #{}") end |
#sync ⇒ Object
Public: Force a sync.
113 114 115 116 117 |
# File 'lib/flipper/cloud/configuration.rb', line 113 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).
121 122 123 |
# File 'lib/flipper/cloud/configuration.rb', line 121 def sync_method sync_secret ? :webhook : :poll end |