Passed
Push — dev ( 1b3874...6a1e3c )
by Konstantinos
03:33
created

green_magic.data.receiver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 28
dl 0
loc 35
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A Backend.create() 0 5 2
A Backend.features_factory() 0 4 1
A Backend.register_as_subclass() 0 6 1
A Backend.computing() 0 4 1
A Backend.commands_manager() 0 4 1
1
import attr
2
import abc
3
4
5
class Backend(abc.ABC):
6
    subclasses = {}
7
8
    @classmethod
9
    def register_as_subclass(cls, backend_type):
10
        def wrapper(subclass):
11
            cls.subclasses[backend_type] = subclass
12
            return subclass
13
        return wrapper
14
15
    @classmethod
16
    def create(cls, backend_type, *args, **kwargs):
17
        if backend_type not in cls.subclasses:
18
            raise ValueError('Bad "Data Backend type" type \'{}\''.format(backend_type))
19
        return cls.subclasses[backend_type](*args, **kwargs)
20
21
    @property
22
    @abc.abstractmethod
23
    def features_factory(self):
24
        raise NotImplementedError
25
26
    @property
27
    @abc.abstractmethod
28
    def commands_manager(self):
29
        raise NotImplementedError
30
31
    @property
32
    @abc.abstractmethod
33
    def computing(self):
34
        raise NotImplementedError
35