module Arturo::FeatureMethods
Constants
- DEFAULT_ATTRIBUTES
- SYMBOL_REGEX
Public Class Methods
new(*args, &block)
click to toggle source
Create a new Feature
Calls superclass method
# File lib/arturo/feature_methods.rb, line 52 def initialize(*args, &block) args[0] = DEFAULT_ATTRIBUTES.merge(args[0].try(:to_h) || {}) super(*args, &block) end
Public Instance Methods
enabled_for?(feature_recipient)
click to toggle source
@param [Object] feature_recipient a User, Account,
or other model with an #id method
@return [true,false] whether or not this feature is enabled
for feature_recipient
@see Arturo::SpecialHandling#whitelisted?
@see Arturo::SpecialHandling#blacklisted?
# File lib/arturo/feature_methods.rb, line 63 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
find_feature(feature_or_symbol)
click to toggle source
Looks up a feature by symbol. Also accepts a Feature
as input. @param [Symbol, Arturo::Feature
] feature_or_symbol a Feature
or the Symbol of a Feature
@return [Arturo::Feature, nil] the Feature
if found, else nil
# File lib/arturo/feature_methods.rb, line 41 def find_feature(feature_or_symbol) feature = to_feature(feature_or_symbol) feature.is_a?(Arturo::NoSuchFeature) ? nil : feature end
inspect()
click to toggle source
# File lib/arturo/feature_methods.rb, line 84 def inspect "<Arturo::Feature #{name}, deployed to #{deployment_percentage}%>" end
last_updated_at()
click to toggle source
# File lib/arturo/feature_methods.rb, line 46 def last_updated_at maximum(:updated_at) end
name()
click to toggle source
# File lib/arturo/feature_methods.rb, line 70 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)
click to toggle source
made public so as to allow for thresholds stored outside of the model
# File lib/arturo/feature_methods.rb, line 89 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_feature(feature_or_symbol)
click to toggle source
Looks up a feature by symbol. Also accepts a Feature
as input. @param [Symbol, Arturo::Feature
] feature_or_symbol a Feature
or the Symbol of a Feature
@return [Arturo::Feature, Arturo::NoSuchFeature
] the Feature
if found, else Arturo::NoSuchFeature
# File lib/arturo/feature_methods.rb, line 31 def to_feature(feature_or_symbol) return feature_or_symbol if feature_or_symbol.kind_of?(self) symbol = feature_or_symbol.to_sym.to_s self.where(:symbol => symbol).first || Arturo::NoSuchFeature.new(symbol) end
to_param()
click to toggle source
# File lib/arturo/feature_methods.rb, line 80 def to_param persisted? ? "#{id}-#{symbol.to_s.parameterize}" : nil end
to_s()
click to toggle source
# File lib/arturo/feature_methods.rb, line 76 def to_s "Feature #{name}" end