Class: Rollout::Legacy
- Inherits:
-
Object
- Object
- Rollout::Legacy
- Defined in:
- lib/rollout/legacy.rb
Instance Method Summary collapse
- #activate_globally(feature) ⇒ Object
- #activate_group(feature, group) ⇒ Object
- #activate_percentage(feature, percentage) ⇒ Object
- #activate_user(feature, user) ⇒ Object
- #active?(feature, user = nil) ⇒ Boolean
- #deactivate_all(feature) ⇒ Object
- #deactivate_globally(feature) ⇒ Object
- #deactivate_group(feature, group) ⇒ Object
- #deactivate_percentage(feature) ⇒ Object
- #deactivate_user(feature, user) ⇒ Object
- #define_group(group, &block) ⇒ Object
- #info(feature = nil) ⇒ Object
-
#initialize(redis) ⇒ Legacy
constructor
A new instance of Legacy.
Constructor Details
#initialize(redis) ⇒ Legacy
Returns a new instance of Legacy.
3 4 5 6 |
# File 'lib/rollout/legacy.rb', line 3 def initialize(redis) @redis = redis @groups = {"all" => lambda { |user| true }} end |
Instance Method Details
#activate_globally(feature) ⇒ Object
8 9 10 |
# File 'lib/rollout/legacy.rb', line 8 def activate_globally(feature) @redis.sadd(global_key, feature) end |
#activate_group(feature, group) ⇒ Object
16 17 18 |
# File 'lib/rollout/legacy.rb', line 16 def activate_group(feature, group) @redis.sadd(group_key(feature), group) end |
#activate_percentage(feature, percentage) ⇒ Object
54 55 56 |
# File 'lib/rollout/legacy.rb', line 54 def activate_percentage(feature, percentage) @redis.set(percentage_key(feature), percentage) end |
#activate_user(feature, user) ⇒ Object
31 32 33 |
# File 'lib/rollout/legacy.rb', line 31 def activate_user(feature, user) @redis.sadd(user_key(feature), user.id) end |
#active?(feature, user = nil) ⇒ Boolean
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rollout/legacy.rb', line 43 def active?(feature, user = nil) if user active_globally?(feature) || user_in_active_group?(feature, user) || user_active?(feature, user) || user_within_active_percentage?(feature, user) else active_globally?(feature) end end |
#deactivate_all(feature) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/rollout/legacy.rb', line 24 def deactivate_all(feature) @redis.del(group_key(feature)) @redis.del(user_key(feature)) @redis.del(percentage_key(feature)) deactivate_globally(feature) end |
#deactivate_globally(feature) ⇒ Object
12 13 14 |
# File 'lib/rollout/legacy.rb', line 12 def deactivate_globally(feature) @redis.srem(global_key, feature) end |
#deactivate_group(feature, group) ⇒ Object
20 21 22 |
# File 'lib/rollout/legacy.rb', line 20 def deactivate_group(feature, group) @redis.srem(group_key(feature), group) end |
#deactivate_percentage(feature) ⇒ Object
58 59 60 |
# File 'lib/rollout/legacy.rb', line 58 def deactivate_percentage(feature) @redis.del(percentage_key(feature)) end |
#deactivate_user(feature, user) ⇒ Object
35 36 37 |
# File 'lib/rollout/legacy.rb', line 35 def deactivate_user(feature, user) @redis.srem(user_key(feature), user.id) end |
#define_group(group, &block) ⇒ Object
39 40 41 |
# File 'lib/rollout/legacy.rb', line 39 def define_group(group, &block) @groups[group.to_s] = block end |
#info(feature = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rollout/legacy.rb', line 62 def info(feature = nil) if feature { :percentage => (active_percentage(feature) || 0).to_i, :groups => active_groups(feature).map { |g| g.to_sym }, :users => active_user_ids(feature), :global => active_global_features } else { :global => active_global_features } end end |