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

Instance Method Details

#add_feature(feature) ⇒ Object

Adds a feature to the assignable.

Parameters:



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_featuresObject

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.

Parameters:

  • identifier (Symbol, String)

    The identifier of the feature.

Returns:

  • (Boolean)

    True if the feature exists, false otherwise.



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.

Parameters:



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