Skip to content

Commit

Permalink
Update AdapterBuilter for Ruby >= 3
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Dec 19, 2023
1 parent 55746f7 commit 93e581b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
20 changes: 4 additions & 16 deletions lib/flipper/adapter_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,12 @@ def initialize(&block)
block.arity == 0 ? instance_eval(&block) : block.call(self) if block
end

if RUBY_VERSION >= '3.0'
def use(klass, *args, **kwargs, &block)
@stack.push ->(adapter) { klass.new(adapter, *args, **kwargs, &block) }
end
else
def use(klass, *args, &block)
@stack.push ->(adapter) { klass.new(adapter, *args, &block) }
end
def use(klass, *args, **kwargs, &block)
@stack.push ->(adapter) { klass.new(adapter, *args, **kwargs, &block) }
end

if RUBY_VERSION >= '3.0'
def store(adapter, *args, **kwargs, &block)
@store = adapter.respond_to?(:call) ? adapter : -> { adapter.new(*args, **kwargs, &block) }
end
else
def store(adapter, *args, &block)
@store = adapter.respond_to?(:call) ? adapter : -> { adapter.new(*args, &block) }
end
def store(adapter, *args, **kwargs, &block)
@store = adapter.respond_to?(:call) ? adapter : -> { adapter.new(*args, **kwargs, &block) }
end

def to_adapter
Expand Down
10 changes: 2 additions & 8 deletions lib/flipper/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,8 @@ def adapter(&block)
end

# An adapter to use to augment the primary storage adapter. See `AdapterBuilder#use`
if RUBY_VERSION >= '3.0'
def use(klass, *args, **kwargs, &block)
@builder.use(klass, *args, **kwargs, &block)
end
else
def use(klass, *args, &block)
@builder.use(klass, *args, &block)
end
def use(klass, *args, **kwargs, &block)
@builder.use(klass, *args, **kwargs, &block)
end

# Controls the default instance for flipper. When used with a block it
Expand Down

0 comments on commit 93e581b

Please sign in to comment.