Class: Arturo::Feature
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Arturo::Feature
- Includes:
- SpecialHandling
- Defined in:
- app/models/arturo/feature.rb
Constant Summary collapse
- SYMBOL_REGEX =
/^[a-zA-z][a-zA-Z0-9_]*$/
- DEFAULT_ATTRIBUTES =
{ :deployment_percentage => 0 }.with_indifferent_access
Class Method Summary collapse
-
.to_feature(feature_or_symbol) ⇒ Arturo::Feature?
Looks up a feature by symbol.
Instance Method Summary collapse
-
#enabled_for?(feature_recipient) ⇒ true, false
Whether or not this feature is enabled for feature_recipient.
-
#initialize(attributes = {}) ⇒ Feature
constructor
Create a new Feature.
- #inspect ⇒ Object
- #name ⇒ Object
- #to_param ⇒ Object
- #to_s ⇒ Object
Methods included from SpecialHandling
Constructor Details
#initialize(attributes = {}) ⇒ Feature
Create a new Feature
32 33 34 |
# File 'app/models/arturo/feature.rb', line 32 def initialize(attributes = {}) super(DEFAULT_ATTRIBUTES.merge(attributes || {})) end |
Class Method Details
.to_feature(feature_or_symbol) ⇒ Arturo::Feature?
Looks up a feature by symbol. Also accepts a Feature as input.
26 27 28 29 |
# File 'app/models/arturo/feature.rb', line 26 def self.to_feature(feature_or_symbol) return feature_or_symbol if feature_or_symbol.kind_of?(self) self.where(:symbol => feature_or_symbol.to_sym).first end |
Instance Method Details
#enabled_for?(feature_recipient) ⇒ true, false
Returns whether or not this feature is enabled for feature_recipient.
42 43 44 45 46 47 |
# File 'app/models/arturo/feature.rb', line 42 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) end |
#inspect ⇒ Object
62 63 64 |
# File 'app/models/arturo/feature.rb', line 62 def inspect "<Arturo::Feature #{name}, deployed to #{deployment_percentage}%>" end |
#name ⇒ Object
49 50 51 52 |
# File 'app/models/arturo/feature.rb', line 49 def name return I18n.translate("arturo.feature.nameless") if symbol.blank? I18n.translate("arturo.feature.#{symbol}", :default => symbol.to_s.titleize) end |
#to_param ⇒ Object
58 59 60 |
# File 'app/models/arturo/feature.rb', line 58 def to_param persisted? ? "#{id}-#{symbol.to_s.parameterize}" : nil end |
#to_s ⇒ Object
54 55 56 |
# File 'app/models/arturo/feature.rb', line 54 def to_s "Feature #{name}" end |