Skip to content

Commit

Permalink
Use memoize option when using Cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Mar 13, 2023
1 parent 61aeebc commit 97ce4d8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/flipper/cloud/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def self.brow_instances
# Public: net/http write timeout for all http requests (default: 5).
attr_accessor :write_timeout

# Public: Memoize adapter operations. Defaults to true.
attr_accessor :memoize

# Public: IO stream to send debug output too. Off by default.
#
# # for example, this would send all http request information to STDOUT
Expand Down Expand Up @@ -85,6 +88,7 @@ def initialize(options = {})
@sync_interval = options.fetch(:sync_interval) { ENV.fetch("FLIPPER_CLOUD_SYNC_INTERVAL", 10).to_f }
@sync_secret = options.fetch(:sync_secret) { ENV["FLIPPER_CLOUD_SYNC_SECRET"] }
@local_adapter = options.fetch(:local_adapter) { Adapters::Memory.new }
@memoize = options.fetch(:memoize, true)
@debug_output = options[:debug_output]
@adapter_block = ->(adapter) { adapter }
self.url = options.fetch(:url) { ENV.fetch("FLIPPER_CLOUD_URL", DEFAULT_URL) }
Expand Down
5 changes: 4 additions & 1 deletion lib/flipper/cloud/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ class DSL < SimpleDelegator

def initialize(cloud_configuration)
@cloud_configuration = cloud_configuration
super Flipper.new(@cloud_configuration.adapter, instrumenter: @cloud_configuration.instrumenter)
super Flipper.new(@cloud_configuration.adapter,
instrumenter: @cloud_configuration.instrumenter,
memoize: @cloud_configuration.memoize
)
end

def sync
Expand Down
3 changes: 2 additions & 1 deletion lib/flipper/cloud/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Engine < Rails::Engine
if ENV["FLIPPER_CLOUD_TOKEN"]
Flipper::Cloud.new(
local_adapter: config.adapter,
instrumenter: app.config.flipper.instrumenter
instrumenter: app.config.flipper.instrumenter,
memoize: app.config.flipper.memoize
)
else
warn "Missing FLIPPER_CLOUD_TOKEN environment variable. Disabling Flipper::Cloud."
Expand Down
23 changes: 23 additions & 0 deletions spec/flipper/cloud/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,27 @@
expect(enable_stub).to have_been_requested
end
end

context "when memoize = :poll" do
let(:local_adapter) do
Flipper::Adapters::OperationLogger.new Flipper::Adapters::Memory.new
end

let(:cloud_configuration) do
cloud_configuration = Flipper::Cloud::Configuration.new({
token: "asdf",
sync_secret: "tasty",
local_adapter: local_adapter,
memoize: :poll
})
end

subject do
described_class.new(cloud_configuration)
end

it "uses a poll adaptor" do
expect(subject.adapter).to be_a(Flipper::Adapters::Poll)
end
end
end

0 comments on commit 97ce4d8

Please sign in to comment.