Module: Detour::Flaggable

Extended by:
ActiveSupport::Concern
Defined in:
lib/detour/flaggable.rb

Instance Method Summary collapse

Instance Method Details

#detour_featuresObject



43
44
45
# File 'lib/detour/flaggable.rb', line 43

def detour_features
  @detour_features ||= []
end

#featuresArray

Returns an array of all features rolled out to the given record.

Examples:

user.features

Returns:



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.

Examples:

if user.has_feature?(:new_user_interface)
  # ...
end

Parameters:

  • feature_name (Symbol)

    The name of the Feature being checked.

  • &block (Proc)

    A block to be called if the user is flagged in to the feature.

Returns:

  • (Boolean)


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