Module: Detour::Flaggable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/detour/flaggable.rb
Instance Method Summary collapse
- #detour_features ⇒ Object
-
#features ⇒ Array
Returns an array of all features rolled out to the given record.
-
#has_feature?(feature_name, &block) ⇒ Boolean
Returns whether or not the object has access to the given feature.
Instance Method Details
#detour_features ⇒ Object
43 44 45 |
# File 'lib/detour/flaggable.rb', line 43 def detour_features @detour_features ||= [] end |
#features ⇒ Array
Returns an array of all features rolled out to the given record.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/detour/flaggable.rb', line 10 def features @features ||= begin features = unfiltered_features defined_group_flags = Detour::DefinedGroupFlag.without_opt_outs(self).where("feature_id IN (?)", features.map(&:id) << -1) # Prevents NOT IN (NULL) defined_group_flags.each do |defined_group_flag| defined_group = Detour::DefinedGroup.by_type(self.class)[defined_group_flag.group_name] unless defined_group && defined_group.test(self) features.delete defined_group_flag.feature end end features end end |
#has_feature?(feature_name, &block) ⇒ Boolean
Returns whether or not the object has access to the given feature. If given a block, it will call the block if the user has access to the feature.
39 40 41 |
# File 'lib/detour/flaggable.rb', line 39 def has_feature?(feature_name, &block) features.map(&:name).include? feature_name.to_s end |