Module: Flipper::Cloud
- Defined in:
- lib/flipper/cloud.rb,
lib/flipper/cloud/dsl.rb,
lib/flipper/cloud/migrate.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, MigrateResult, Telemetry
Constant Summary collapse
- DEFAULT_CLOUD_URL =
"https://www.flippercloud.io".freeze
Class Method Summary collapse
- .app(flipper = nil, options = {}) {|builder| ... } ⇒ Object
-
.migrate(flipper = Flipper, app_name: nil) ⇒ Object
Public: Migrate features to Flipper Cloud.
-
.new(options = {}) {|configuration| ... } ⇒ Object
Public: Returns a new Flipper instance with an http adapter correctly configured for flipper cloud.
-
.push(token, flipper = Flipper) ⇒ Object
Public: Push features to an existing Flipper Cloud project.
-
.set_default ⇒ Object
Private: Configure Flipper to use Cloud by default.
Class Method Details
.app(flipper = nil, options = {}) {|builder| ... } ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/flipper/cloud.rb', line 24 def self.app(flipper = nil, = {}) env_key = .fetch(:env_key, 'flipper') = .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, .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 |
.migrate(flipper = Flipper, app_name: nil) ⇒ Object
Public: Migrate features to Flipper Cloud.
flipper - The Flipper instance to export features from (default: Flipper). app_name - Optional String name of the application.
Returns a MigrateResult with code, url, and message.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/flipper/cloud/migrate.rb', line 16 def self.migrate(flipper = Flipper, app_name: nil) export = flipper.export(format: :json, version: 1) payload = { export: Typecast.from_json(export.contents), metadata: {app_name: app_name}, } client = build_client("/api") response = client.post("/migrate", Typecast.to_gzip(Typecast.to_json(payload))) body = Typecast.from_json(response.body) rescue nil MigrateResult.new( code: response.code.to_i, url: body&.dig("url"), message: body&.dig("error"), ) 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.
18 19 20 21 22 |
# File 'lib/flipper/cloud.rb', line 18 def self.new( = {}) configuration = Configuration.new() yield configuration if block_given? DSL.new(configuration) end |
.push(token, flipper = Flipper) ⇒ Object
Public: Push features to an existing Flipper Cloud project.
token - The String token for the Cloud environment. flipper - The Flipper instance to export features from (default: Flipper).
Returns a MigrateResult with code and message.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/flipper/cloud/migrate.rb', line 40 def self.push(token, flipper = Flipper) export = flipper.export(format: :json, version: 1) client = build_client("/adapter", headers: { "flipper-cloud-token" => token, }) response = client.post("/import", Typecast.to_gzip(export.contents)) body = Typecast.from_json(response.body) rescue nil MigrateResult.new( code: response.code.to_i, url: nil, message: body&.dig("error"), ) end |