Module: Flipper::Cloud

Defined in:
lib/flipper/cloud.rb,
lib/flipper/cloud/dsl.rb,
lib/flipper/cloud/telemetry.rb,
lib/flipper/cloud/middleware.rb,
lib/flipper/cloud/configuration.rb,
lib/flipper/cloud/message_verifier.rb,
lib/flipper/cloud/telemetry/metric.rb,
lib/flipper/cloud/telemetry/submitter.rb,
lib/flipper/cloud/telemetry/instrumenter.rb,
lib/flipper/cloud/telemetry/backoff_policy.rb,
lib/flipper/cloud/telemetry/metric_storage.rb

Defined Under Namespace

Classes: Configuration, DSL, MessageVerifier, Middleware, Telemetry

Class Method Summary collapse

Class Method Details

.app(flipper = nil, options = {}) {|builder| ... } ⇒ Object

Yields:

  • (builder)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/flipper/cloud.rb', line 23

def self.app(flipper = nil, options = {})
  env_key = options.fetch(:env_key, 'flipper')
  memoizer_options = options.fetch(:memoizer_options, {})

  app = ->(_) { [404, { Rack::CONTENT_TYPE => 'application/json'.freeze }, ['{}'.freeze]] }
  builder = Rack::Builder.new
  yield builder if block_given?
  builder.use Flipper::Middleware::SetupEnv, flipper, env_key: env_key
  builder.use Flipper::Middleware::Memoizer, memoizer_options.merge(env_key: env_key)
  builder.use Flipper::Cloud::Middleware, env_key: env_key
  builder.run app
  klass = self
  app = builder.to_app
  app.define_singleton_method(:inspect) { klass.inspect } # pretty rake routes output
  app
end

.new(options = {}) {|configuration| ... } ⇒ Object

Public: Returns a new Flipper instance with an http adapter correctly configured for flipper cloud.

token - The String token for the environment from the website. options - The Hash of options. See Flipper::Cloud::Configuration. block - The block that configuration will be yielded to allowing you to

customize this cloud instance and its adapter.

Yields:



17
18
19
20
21
# File 'lib/flipper/cloud.rb', line 17

def self.new(options = {})
  configuration = Configuration.new(options)
  yield configuration if block_given?
  DSL.new(configuration)
end

.set_defaultObject

Private: Configure Flipper to use Cloud by default



41
42
43
44
45
46
47
48
49
# File 'lib/flipper/cloud.rb', line 41

def self.set_default
  if ENV["FLIPPER_CLOUD_TOKEN"]
    Flipper.configure do |config|
      config.default do
        self.new(local_adapter: config.adapter)
      end
    end
  end
end