mongoid_feature_flags 0.1.19 → 0.1.20
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/lib/mongoid_feature_flags.rb +40 -42
- data/spec/spec_helper.rb +1 -0
- metadata +1 -1
data/Gemfile
CHANGED
@@ -23,53 +23,51 @@ module Mongoid
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
self.feature_flags[flag] = true
|
31
|
-
end
|
32
|
-
self.save
|
33
|
-
end
|
34
|
-
|
35
|
-
def remove_feature(*flags)
|
36
|
-
self.feature_flags ||= {}
|
37
|
-
flags.each do |flag|
|
38
|
-
self.feature_flags[flag] = false
|
39
|
-
end
|
40
|
-
self.save
|
26
|
+
def add_feature(*flags)
|
27
|
+
self.feature_flags ||= {}
|
28
|
+
flags.each do |flag|
|
29
|
+
self.feature_flags[flag] = true
|
41
30
|
end
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
if required_features.any? { |feature| my_features[feature] }
|
50
|
-
block.present? ? block.yield : true
|
51
|
-
end
|
31
|
+
self.save
|
32
|
+
end
|
33
|
+
|
34
|
+
def remove_feature(*flags)
|
35
|
+
self.feature_flags ||= {}
|
36
|
+
flags.each do |flag|
|
37
|
+
self.feature_flags[flag] = false
|
52
38
|
end
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
39
|
+
self.save
|
40
|
+
end
|
41
|
+
|
42
|
+
def features
|
43
|
+
inherited_feature_flags.merge(self.feature_flags)
|
44
|
+
end
|
45
|
+
|
46
|
+
def feature?(*required_features, &block)
|
47
|
+
my_features = features
|
48
|
+
if required_features.any? { |feature| my_features[feature] }
|
49
|
+
block.present? ? block.yield : true
|
59
50
|
end
|
60
|
-
|
61
|
-
|
62
|
-
|
51
|
+
end
|
52
|
+
|
53
|
+
def not_feature?(*unrequired_features, &block)
|
54
|
+
my_features = features
|
55
|
+
if unrequired_features.none? { |feature| my_features[feature] }
|
56
|
+
block.present? ? block.yield : true
|
63
57
|
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def feature_flag_validate_flag(*flag)
|
61
|
+
raise(InvalidFlagName, "Flags must be a symbol") if !flag.any? { |f| f.is_a?(Symbol) }
|
62
|
+
end
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
64
|
+
def inherited_feature_flags
|
65
|
+
if self.class.instance_variable_defined?("@feature_flag_parents")
|
66
|
+
self.class.instance_variable_get("@feature_flag_parents").inject({}) do |flag_hash, relative|
|
67
|
+
if self.respond_to?(relative) && self.send(relative).present? && self.send(relative).respond_to?(:feature_flags)
|
68
|
+
flag_hash.merge(self.send(relative).send(:feature_flags))
|
69
|
+
else
|
70
|
+
flag_hash
|
73
71
|
end
|
74
72
|
end
|
75
73
|
end
|
data/spec/spec_helper.rb
CHANGED