Class: Binflip
- Inherits:
-
Object
show all
- Defined in:
- lib/binflip.rb
Instance Method Summary
collapse
Constructor Details
#initialize(rollout = nil) ⇒ Binflip
Returns a new instance of Binflip.
17
18
19
20
21
|
# File 'lib/binflip.rb', line 17
def initialize(rollout=nil)
if rollout && rollout.is_a?(Rollout)
@rollout = rollout
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
68
69
70
71
72
73
74
75
|
# File 'lib/binflip.rb', line 68
def method_missing(meth, *args, &block)
if rollout?
@rollout.send(meth, *args, &block)
cleanup_feature_set! if (meth =~ /(:de)?activate/)
else
super
end
end
|
Instance Method Details
#activate_group(feature, group) ⇒ Object
51
52
53
54
|
# File 'lib/binflip.rb', line 51
def activate_group(feature, group)
@rollout.activate_group(feature, group)
feature_set_add(feature)
end
|
#activate_user(feature, user) ⇒ Object
56
57
58
59
|
# File 'lib/binflip.rb', line 56
def activate_user(feature, user)
@rollout.activate_user(feature, user)
feature_set_add(feature)
end
|
#active?(feature, user = nil) ⇒ Boolean
35
36
37
38
39
40
41
|
# File 'lib/binflip.rb', line 35
def active?(feature, user=nil)
if environment_active?(feature) && rollout? && user
@rollout.active?(feature, user)
else
environment_active?(feature)
end
end
|
#active_features(user = nil) ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/binflip.rb', line 43
def active_features(user=nil)
active_features ||= {}
features.each do |feature|
active_features[feature] = active?(feature, user)
end
active_features
end
|
#cleanup_feature_set! ⇒ Object
61
62
63
64
65
66
|
# File 'lib/binflip.rb', line 61
def cleanup_feature_set!
features_rollout.each do |feature|
unused_feature = { :percentage => 0, :groups => [], :users => [] }
feature_set_del(feature) if (@source.info(feature) == unused_feature)
end
end
|
#redis ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/binflip.rb', line 27
def redis
@redis ||= if rollout?
@rollout.instance_variable_get(:@redis)
else
FauxRedis.new
end
end
|
#rollout? ⇒ Boolean
23
24
25
|
# File 'lib/binflip.rb', line 23
def rollout?
!! @rollout
end
|