Skip to content

Commit

Permalink
use Forwardable for all the feature flag delegation
Browse files Browse the repository at this point in the history
Be clear about:

1. Cannot instantiate a Feature object (module instead of class)
2. List of methods delegated to the "feature flag adapter" which
   happens to be Rollout in our implementation.

Signed-off-by: Robb Kidd <rkidd@chef.io>
  • Loading branch information
robbkidd committed Oct 13, 2017
1 parent 6d4e541 commit d15e3a2
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions src/supermarket/app/lib/feature.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
require 'redis'

class Feature
@rollout = nil

def self.active?(*args)
rollout.active?(*args)
end
module Feature
extend Forwardable

def self.activate(*args)
rollout.activate(*args)
end
module_function(*def_delegators('Feature.adapter', :active?, :activate, :deactivate))

def self.deactivate(*args)
rollout.deactivate(*args)
end
@rollout = nil

def self.rollout
def self.adapter
return @rollout if @rollout

redis_url = ENV['REDIS_URL'] || 'redis://localhost:6379/0/supermarket'
Expand All @@ -42,6 +34,4 @@ def self.rollout

@rollout
end

private_class_method :rollout
end

0 comments on commit d15e3a2

Please sign in to comment.