Skip to content

Commit

Permalink
Remove kwarg for Strict handler, use arg or block
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Sep 20, 2023
1 parent 0f92e8a commit 944d174
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/flipper/adapters/strict.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def initialize(name)

def_delegators :@adapter, :features, :get_all, :add, :remove, :clear, :enable, :disable

def initialize(adapter, handler: :raise)
def initialize(adapter, handler = nil, &block)
@name = :strict
@adapter = adapter
@handler = handler.is_a?(Symbol) ? HANDLERS.fetch(handler) : handler
@handler = block || HANDLERS.fetch(handler)
end

def get(feature)
Expand Down
14 changes: 7 additions & 7 deletions spec/flipper/adapters/strict_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
let(:feature) { flipper[:unknown] }

it_should_behave_like 'a flipper adapter' do
subject { described_class.new(Flipper::Adapters::Memory.new, handler: :noop) }
subject { described_class.new(Flipper::Adapters::Memory.new, :noop) }
end

context "handler: :raise" do
subject { described_class.new(Flipper::Adapters::Memory.new, handler: :raise) }
context "handler = :raise" do
subject { described_class.new(Flipper::Adapters::Memory.new, :raise) }

context "#get" do
it "raises an error for unknown feature" do
Expand All @@ -22,8 +22,8 @@
end
end

context "handler: :warn" do
subject { described_class.new(Flipper::Adapters::Memory.new, handler: :warn) }
context "handler = :warn" do
subject { described_class.new(Flipper::Adapters::Memory.new, :warn) }

context "#get" do
it "raises an error for unknown feature" do
Expand All @@ -38,10 +38,10 @@
end
end

context "handler: Proc" do
context "handler = Block" do
let(:unknown_features) { [] }
subject do
described_class.new(Flipper::Adapters::Memory.new, handler: ->(feature) { unknown_features << feature.key})
described_class.new(Flipper::Adapters::Memory.new) { |feature| unknown_features << feature.key}
end


Expand Down

0 comments on commit 944d174

Please sign in to comment.