Module: Togglefy::Assignable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/togglefy/assignable.rb
Overview
The Assignable module provides functionality for models to relate with features. It includes methods to add, remove, and query features, as well as ActiveRecord scopes.
Instance Method Summary collapse
-
#add_feature(feature) ⇒ Object
Adds a feature to the assignable.
-
#clear_features ⇒ Object
Clears all features from the assignable.
-
#feature?(identifier) ⇒ Boolean
(also: #has_feature?)
Checks if the assignable has a specific feature.
-
#remove_feature(feature) ⇒ Object
Removes a feature from the assignable.
Instance Method Details
#add_feature(feature) ⇒ Object
Adds a feature to the assignable.
49 50 51 52 |
# File 'lib/togglefy/assignable.rb', line 49 def add_feature(feature) feature = find_feature!(feature) features << feature unless has_feature?(feature.identifier) end |
#clear_features ⇒ Object
Clears all features from the assignable.
63 64 65 |
# File 'lib/togglefy/assignable.rb', line 63 def clear_features features.destroy_all end |
#feature?(identifier) ⇒ Boolean Also known as: has_feature?
Checks if the assignable has a specific feature.
41 42 43 |
# File 'lib/togglefy/assignable.rb', line 41 def feature?(identifier) features.active.exists?(identifier: identifier.to_s) end |
#remove_feature(feature) ⇒ Object
Removes a feature from the assignable.
57 58 59 60 |
# File 'lib/togglefy/assignable.rb', line 57 def remove_feature(feature) feature = find_feature!(feature) features.destroy(feature) if has_feature?(feature.identifier) end |