Module: Detour::Flaggable
- Defined in:
- lib/detour/flaggable.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #detour_features ⇒ Object
-
#has_feature?(feature_name, &block) ⇒ Boolean
Returns whether or not the object has access to the given feature.
Instance Method Details
#detour_features ⇒ Object
63 64 65 |
# File 'lib/detour/flaggable.rb', line 63 def detour_features @detour_features ||= [] 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.
If an exception is raised in the block, it will increment the ‘failure_count` of the feature and raise the exception.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/detour/flaggable.rb', line 34 def has_feature?(feature_name, &block) if detour_features.include? feature_name.to_s match = true else feature = Detour::Feature.find_by_name(feature_name) return false unless feature opt_out = opt_out_flags.find_by_feature_id(feature.id) return false if opt_out match = feature.match? self if match detour_features << feature.name.to_s end end if match && block_given? begin yield rescue => e feature.increment! :failure_count raise e end end match end |