Class: FeatureToggle::Features
- Inherits:
-
Object
- Object
- FeatureToggle::Features
- Defined in:
- lib/feature_toggle/features.rb
Instance Method Summary collapse
- #[](feature_name) ⇒ Object
- #activate(*feature_names) ⇒ Object
- #active?(feature_name) ⇒ Boolean
- #active_action?(controller, action) ⇒ Boolean
- #deactivate(*feature_names) ⇒ Object
-
#initialize(features) ⇒ Features
constructor
A new instance of Features.
Constructor Details
#initialize(features) ⇒ Features
Returns a new instance of Features.
4 5 6 7 8 |
# File 'lib/feature_toggle/features.rb', line 4 def initialize(features) @features = features @actions = build_actions_feature_map(features) @deactivated_features = Set.new end |
Instance Method Details
#[](feature_name) ⇒ Object
10 11 12 |
# File 'lib/feature_toggle/features.rb', line 10 def [](feature_name) @features[feature_name] end |
#activate(*feature_names) ⇒ Object
14 15 16 17 18 |
# File 'lib/feature_toggle/features.rb', line 14 def activate(*feature_names) feature_names.each do |feature_name| @deactivated_features.delete(feature_name) if valid?(feature_name) end end |
#active?(feature_name) ⇒ Boolean
31 32 33 |
# File 'lib/feature_toggle/features.rb', line 31 def active?(feature_name) !@deactivated_features.include?(feature_name) end |
#active_action?(controller, action) ⇒ Boolean
26 27 28 29 |
# File 'lib/feature_toggle/features.rb', line 26 def active_action?(controller, action) feature = @actions["#{controller}:#{action}"] || @actions["#{controller}:*"] active?(feature) end |
#deactivate(*feature_names) ⇒ Object
20 21 22 23 24 |
# File 'lib/feature_toggle/features.rb', line 20 def deactivate(*feature_names) feature_names.each do |feature_name| @deactivated_features << feature_name if valid?(feature_name) end end |