This repository has been archived by the owner on May 24, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added some examples and explained internals.
- Loading branch information
1 parent
ddca002
commit 3fe611e
Showing
5 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'pathname' | ||
require 'logger' | ||
|
||
root_path = Pathname(__FILE__).dirname.join('..').expand_path | ||
lib_path = root_path.join('lib') | ||
$:.unshift(lib_path) | ||
|
||
require 'flipper/adapters/redis' | ||
client = Redis.new | ||
adapter = Flipper::Adapters::Redis.new(client) | ||
flipper = Flipper.new(adapter) | ||
|
||
flipper[:stats].enable | ||
|
||
if flipper[:stats].enabled? | ||
puts "Enabled!" | ||
else | ||
puts "Disabled!" | ||
end | ||
|
||
flipper[:stats].disable | ||
|
||
if flipper[:stats].enabled? | ||
puts "Enabled!" | ||
else | ||
puts "Disabled!" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require 'pp' | ||
require 'pathname' | ||
require 'logger' | ||
|
||
root_path = Pathname(__FILE__).dirname.join('..').expand_path | ||
lib_path = root_path.join('lib') | ||
$:.unshift(lib_path) | ||
|
||
require 'flipper/adapters/redis' | ||
require 'redis/namespace' | ||
|
||
client = Redis.new | ||
namespaced_client = Redis::Namespace.new(:flipper, :redis => client) | ||
adapter = Flipper::Adapters::Redis.new(namespaced_client) | ||
flipper = Flipper.new(adapter) | ||
|
||
# Register a few groups. | ||
Flipper.register(:admins) { |thing| thing.admin? } | ||
Flipper.register(:early_access) { |thing| thing.early_access? } | ||
|
||
# Create a user class that has flipper_id instance method. | ||
User = Struct.new(:flipper_id) | ||
|
||
flipper[:stats].enable | ||
flipper[:stats].enable flipper.group(:admins) | ||
flipper[:stats].enable flipper.group(:early_access) | ||
flipper[:stats].enable User.new('25') | ||
flipper[:stats].enable User.new('90') | ||
flipper[:stats].enable User.new('180') | ||
flipper[:stats].enable flipper.random(15) | ||
flipper[:stats].enable flipper.actors(45) | ||
|
||
flipper[:search].enable | ||
|
||
print '# all keys: ' | ||
pp namespaced_client.keys | ||
puts | ||
# all keys: ["stats", "flipper_features", "search"] | ||
|
||
puts '# stats keys' | ||
pp namespaced_client.hgetall('stats') | ||
puts | ||
# stats keys | ||
# {"boolean"=>"true", | ||
# "groups/admins"=>"1", | ||
# "actors/25"=>"1", | ||
# "percentage_of_random"=>"15", | ||
# "percentage_of_actors"=>"45", | ||
# "groups/early_access"=>"1", | ||
# "actors/90"=>"1", | ||
# "actors/180"=>"1"} | ||
|
||
puts '# search keys' | ||
pp namespaced_client.hgetall('search') | ||
puts | ||
# search keys | ||
# {"boolean"=>"true"} | ||
|
||
puts '# flipper get of feature' | ||
pp adapter.get(flipper[:stats]) | ||
# flipper get of feature | ||
# {:boolean=>"true", | ||
# :groups=>#<Set: {"admins", "early_access"}>, | ||
# :actors=>#<Set: {"25", "90", "180"}>, | ||
# :percentage_of_actors=>"45", | ||
# :percentage_of_random=>"15"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters