-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement flipper via singleton + updated readme docs
- Loading branch information
1 parent
7d1f646
commit 49ae8fe
Showing
4 changed files
with
92 additions
and
35 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
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 |
---|---|---|
@@ -1,27 +1,42 @@ | ||
require "./flipper/*" | ||
|
||
class Flipper | ||
def initialize(@adapter : Kiwi::Store) | ||
class AdapterNotSet < Exception | ||
end | ||
|
||
def enable(feature) | ||
@adapter.set(feature.to_s, "true") == "true" | ||
def self.adapter=(adapter : Kiwi::Store) | ||
@@adapter = adapter | ||
end | ||
|
||
def disable(feature) | ||
@adapter.set(feature.to_s, "false") == "false" | ||
def self.adapter | ||
raise Flipper::AdapterNotSet.new unless @@adapter | ||
@@adapter | ||
end | ||
|
||
def enabled?(feature) | ||
stored_value = @adapter.get(feature.to_s) | ||
if stored_value.nil? || stored_value == "false" | ||
false | ||
elsif stored_value == "true" | ||
true | ||
def self.enable(feature) | ||
adapter.try do |adapter| | ||
adapter.set(feature.to_s, "true") == "true" | ||
end | ||
end | ||
|
||
def disabled?(feature) | ||
def self.disable(feature) | ||
adapter.try do |adapter| | ||
adapter.set(feature.to_s, "false") == "false" | ||
end | ||
end | ||
|
||
def self.enabled?(feature) | ||
adapter.try do |adapter| | ||
stored_value = adapter.get(feature.to_s) | ||
if stored_value.nil? || stored_value == "false" | ||
false | ||
elsif stored_value == "true" | ||
true | ||
end | ||
end | ||
end | ||
|
||
def self.disabled?(feature) | ||
!enabled?(feature) | ||
end | ||
end |