Class: Featurer::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/featurer/adapter.rb

Direct Known Subclasses

RedisAdapter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#configObject (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

Parameters:

  • _feature

    the name of the feature as will be used when questioning if the feature is #on?

  • _matching_value

    the value that will be used to match when calling #on?. Valid values are:

Raises:

  • (NotImplementedError)


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.

Raises:

  • (NotImplementedError)


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)

Parameters:

  • _value (defaults to: true)

    the value that will be used when matching against the stored matching_values

Raises:

  • (NotImplementedError)


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

Parameters:

  • _feature

    the feature name, as provided when calling #add or #register

  • _value (defaults to: true)

    the value that will be used when matching against the stored matching_value for the given feature

Returns:

  • (Boolean)

    a Boolean that depends on the _value provided

Raises:

  • (NotImplementedError)


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.

Parameters:

  • _feature

    the feature to register

  • _matching_value (defaults to: true)

    the new matching_value for the feature that replaces any existing matching_value on it

Raises:

  • (NotImplementedError)


61
62
63
# File 'lib/featurer/adapter.rb', line 61

def register(_feature, _matching_value = true)
  raise NotImplementedError
end