Class: Flipper::Cloud::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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(options = {})
  setup_auth options
  setup_log options
  setup_http options
  setup_sync options
  setup_adapter options
  setup_telemetry options
end

Instance Attribute Details

#debug_outputObject

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

#instrumenterObject

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_adapterObject

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

#loggerObject

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_enabledObject

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_timeoutObject

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_timeoutObject

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_intervalObject

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_secretObject

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

#telemetryObject

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_enabledObject

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

#tokenObject

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

#urlObject

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_timeoutObject

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_clientObject

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(message, level: :debug)
  return unless logging_enabled
  logger.send(level, "name=flipper_cloud #{message}")
end

#syncObject

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_methodObject

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