Class: Featurer::Adapter
- Inherits:
-
Object
- Object
- Featurer::Adapter
- Defined in:
- lib/featurer/adapter.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
-
#add(_feature, _matching_value) ⇒ Object
Attaches a new matching value to the given feature.
-
#delete(_feature) ⇒ Object
Completely removes a feature from the system.
-
#enabled_features(_value = true) ⇒ Object
Returns an array with all the enabled features that match the given value (or just the global ones if no value is provided).
-
#initialize(config = {}) ⇒ Adapter
constructor
A new instance of Adapter.
-
#on?(_feature, _value = true) ⇒ Boolean
Returns true if the feature has a matching value attached wich matches the given value.
-
#register(_feature, _matching_value = true) ⇒ Object
First deletes the given _feature and then creates it again with only the provided _matching_value attached.
Constructor Details
#initialize(config = {}) ⇒ Adapter
Returns a new instance of Adapter.
10 11 12 |
# File 'lib/featurer/adapter.rb', line 10 def initialize(config = {}) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
4 5 6 |
# File 'lib/featurer/adapter.rb', line 4 def config @config end |
Class Method Details
.inherited(klass) ⇒ Object
6 7 8 |
# File 'lib/featurer/adapter.rb', line 6 def self.inherited(klass) AdapterManager.add_adapter klass end |
Instance Method Details
#add(_feature, _matching_value) ⇒ Object
Attaches a new matching value to the given feature. If the feature doesn’t exist, the adapter should create it automatically. Feature matching_values must be matched in the order they were added.
> - true: it will match any value (ie: the feature enabled globally)
> - false: the feature is disabled globally
> - regular expression: matched when calling #on?, if regular expression is passed
> - other types: matched literally when calling #on?, based on the #to_s representation
24 25 26 |
# File 'lib/featurer/adapter.rb', line 24 def add(_feature, _matching_value) raise NotImplementedError end |
#delete(_feature) ⇒ Object
Completely removes a feature from the system. If the feature doesn’t exist, the adapter should not fail.
30 31 32 |
# File 'lib/featurer/adapter.rb', line 30 def delete(_feature) raise NotImplementedError end |
#enabled_features(_value = true) ⇒ Object
Returns an array with all the enabled features that match the given value (or just the global ones if no value is provided)
53 54 55 |
# File 'lib/featurer/adapter.rb', line 53 def enabled_features(_value = true) raise NotImplementedError end |
#on?(_feature, _value = true) ⇒ Boolean
Returns true if the feature has a matching value attached wich matches the given value.
> - true if _value is nil and the _feature has a matching_value of true
> - true if _value is an integer and the _feature has that exact integer attached as a matching_value
> - true if _value is a string and the _feature has a matching_value which is a regexp that matches _value
> - true if _value is any other type and the _feature has a matching_value which has the same exact #to_s
> representation
> - false in any other case
45 46 47 |
# File 'lib/featurer/adapter.rb', line 45 def on?(_feature, _value = true) raise NotImplementedError end |
#register(_feature, _matching_value = true) ⇒ Object
First deletes the given _feature and then creates it again with only the provided _matching_value attached.
61 62 63 |
# File 'lib/featurer/adapter.rb', line 61 def register(_feature, _matching_value = true) raise NotImplementedError end |