Module: Arturo::FeatureMethods
- Extended by:
- ActiveSupport::Concern
- Includes:
- SpecialHandling
- Included in:
- Feature
- Defined in:
- lib/arturo/feature_methods.rb
Constant Summary collapse
- SYMBOL_REGEX =
/^[a-zA-z][a-zA-Z0-9_]*$/
- DEFAULT_ATTRIBUTES =
{ :deployment_percentage => 0 }.with_indifferent_access
Instance Method Summary collapse
-
#enabled_for?(feature_recipient) ⇒ true, false
Whether or not this feature is enabled for feature_recipient.
-
#initialize(*args, &block) ⇒ Object
Create a new Feature.
- #inspect ⇒ Object
- #name ⇒ Object
-
#passes_threshold?(feature_recipient, threshold) ⇒ Boolean
made public so as to allow for thresholds stored outside of the model.
- #to_param ⇒ Object
- #to_s ⇒ Object
Instance Method Details
#enabled_for?(feature_recipient) ⇒ true, false
Returns whether or not this feature is enabled for feature_recipient.
62 63 64 65 66 67 |
# File 'lib/arturo/feature_methods.rb', line 62 def enabled_for?(feature_recipient) return false if feature_recipient.nil? return false if blacklisted?(feature_recipient) return true if whitelisted?(feature_recipient) passes_threshold?(feature_recipient, deployment_percentage || 0) end |
#initialize(*args, &block) ⇒ Object
Create a new Feature
51 52 53 54 |
# File 'lib/arturo/feature_methods.rb', line 51 def initialize(*args, &block) args[0] = DEFAULT_ATTRIBUTES.merge(args[0].try(:to_h) || {}) super(*args, &block) end |
#inspect ⇒ Object
83 84 85 |
# File 'lib/arturo/feature_methods.rb', line 83 def inspect "<Arturo::Feature #{name}, deployed to #{deployment_percentage}%>" end |
#name ⇒ Object
69 70 71 72 73 |
# File 'lib/arturo/feature_methods.rb', line 69 def name return I18n.translate("arturo.feature.nameless") if symbol.blank? I18n.translate("arturo.feature.#{symbol}", :default => symbol.to_s.titleize) end |
#passes_threshold?(feature_recipient, threshold) ⇒ Boolean
made public so as to allow for thresholds stored outside of the model
88 89 90 91 92 |
# File 'lib/arturo/feature_methods.rb', line 88 def passes_threshold?(feature_recipient, threshold) return true if threshold == 100 return false if threshold == 0 || !feature_recipient.id (((feature_recipient.id + (self.id || 1) + 17) * 13) % 100) < threshold end |
#to_param ⇒ Object
79 80 81 |
# File 'lib/arturo/feature_methods.rb', line 79 def to_param persisted? ? "#{id}-#{symbol.to_s.parameterize}" : nil end |
#to_s ⇒ Object
75 76 77 |
# File 'lib/arturo/feature_methods.rb', line 75 def to_s "Feature #{name}" end |