-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added flagset to split cach repository
- Loading branch information
Showing
5 changed files
with
182 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'set' | ||
|
||
module SplitIoClient | ||
module Cache | ||
module Filter | ||
class FlagSetsFilter | ||
def initialize(flag_sets = []) | ||
@flag_sets = Set.new(flag_sets) | ||
@should_filter = @flag_sets.any? | ||
end | ||
|
||
def should_filter? | ||
@should_filter | ||
end | ||
|
||
def flag_set_exist?(flag_set) | ||
return true unless @should_filter | ||
|
||
if not flag_set.is_a?(String) or flag_set.empty? | ||
return false | ||
end | ||
|
||
@flag_sets.intersection([flag_set]).any? | ||
end | ||
|
||
def intersect?(flag_sets) | ||
return true unless @should_filter | ||
|
||
if not flag_sets.is_a?(Array) or flag_sets.empty? | ||
return false | ||
end | ||
|
||
@flag_sets.intersection(Set.new(flag_sets)).any? | ||
end | ||
end | ||
end | ||
end | ||
end |
38 changes: 38 additions & 0 deletions
38
lib/splitclient-rb/cache/repositories/flag_sets_repository.rb
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,38 @@ | ||
require 'concurrent' | ||
|
||
module SplitIoClient | ||
module Cache | ||
module Repositories | ||
class FlagSets | ||
def initialize(flag_sets = []) | ||
@sets_feature_flag_map = {} | ||
flag_sets.each{ |flag_set| @sets_feature_flag_map[flag_set] = Set[] } | ||
end | ||
|
||
def flag_set_exist?(flag_set) | ||
@sets_feature_flag_map.keys.include? flag_set | ||
end | ||
|
||
def get_flag_set(flag_set) | ||
@sets_feature_flag_map[flag_set] | ||
end | ||
|
||
def add_flag_set(flag_set) | ||
@sets_feature_flag_map[flag_set] = Set[] if !flag_set_exist?(flag_set) | ||
end | ||
|
||
def remove_flag_set(flag_set) | ||
@sets_feature_flag_map.delete(flag_set) if flag_set_exist?(flag_set) | ||
end | ||
|
||
def add_feature_flag_to_flag_set(flag_set, feature_flag) | ||
@sets_feature_flag_map[flag_set].add(feature_flag) if flag_set_exist?(flag_set) | ||
end | ||
|
||
def remove_feature_flag_to_flag_set(flag_set, feature_flag) | ||
@sets_feature_flag_map[flag_set].delete(feature_flag) if flag_set_exist?(flag_set) | ||
end | ||
end | ||
end | ||
end | ||
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
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