2015-06-16 10:37:57 +03:00
|
|
|
Static providers
|
|
|
|
----------------
|
|
|
|
|
|
|
|
Static providers are family of providers that return their values "as is".
|
|
|
|
There are four types of static providers:
|
|
|
|
|
|
|
|
- ``Class``
|
|
|
|
- ``Object``
|
|
|
|
- ``Function``
|
|
|
|
- ``Value``
|
|
|
|
|
|
|
|
All of them have the same behaviour, but usage of anyone is predicted by
|
|
|
|
readability and providing object's type.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
"""`Static` providers example."""
|
|
|
|
|
|
|
|
from objects.providers import Class
|
|
|
|
from objects.providers import Object
|
|
|
|
from objects.providers import Function
|
|
|
|
from objects.providers import Value
|
|
|
|
|
|
|
|
|
2015-06-18 14:55:13 +03:00
|
|
|
# Provides class - `object`:
|
2015-06-16 10:37:57 +03:00
|
|
|
cls_provider = Class(object)
|
|
|
|
assert cls_provider() is object
|
|
|
|
|
2015-06-18 14:55:13 +03:00
|
|
|
# Provides object - `object()`:
|
2015-06-16 10:37:57 +03:00
|
|
|
object_provider = Object(object())
|
|
|
|
assert isinstance(object_provider(), object)
|
|
|
|
|
2015-06-18 14:55:13 +03:00
|
|
|
# Provides function - `len`:
|
2015-06-16 10:37:57 +03:00
|
|
|
function_provider = Function(len)
|
|
|
|
assert function_provider() is len
|
|
|
|
|
2015-06-18 14:55:13 +03:00
|
|
|
# Provides value - `123`:
|
2015-06-16 10:37:57 +03:00
|
|
|
value_provider = Value(123)
|
|
|
|
assert value_provider() == 123
|
|
|
|
|