Completed
Push — master ( eac9d6...cda706 )
by Jace
11s
created

TemplateModel   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 25
ccs 12
cts 12
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 3 1
A domain() 0 11 1
1 1
import os
2
3 1
import yorm
0 ignored issues
show
Configuration introduced by
The import yorm could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
4
5 1
from ..domain import Template
6
7
8 1
@yorm.attr(all=yorm.types.String)
0 ignored issues
show
Coding Style introduced by
This class has no __init__ method.
Loading history...
9 1
class StringList(yorm.types.List):
10 1
    pass
11
12
13 1
@yorm.attr(key=yorm.types.String)
14 1
@yorm.attr(name=yorm.types.String)
15 1
@yorm.attr(default=StringList)
16 1
@yorm.attr(link=yorm.types.String)
17 1
@yorm.attr(aliases=StringList)
18 1
@yorm.attr(regexes=StringList)
19 1
@yorm.sync("{self.root}/{self.key}/config.yml")
20
class TemplateModel:
21
    """Persistence model for templates."""
22
23 1
    def __init__(self, key, root):
24 1
        self.key = key
25 1
        self.root = root
26
27 1
    @property
28
    def domain(self):
29
        # pylint: disable=no-member
30 1
        return Template(
31
            key=self.key,
32
            name=self.name,
33
            lines=self.default,
34
            aliases=self.aliases,
35
            patterns=self.regexes,
36
            link=self.link,
37
            root=self.root,
38
        )
39
40
41 1
def load_before(func):
42 1
    def wrapped(self, *args, **kwargs):
43
        # pylint: disable=protected-access
44 1
        if self._items is None:
45 1
            self._load()
46 1
        return func(self, *args, **kwargs)
47 1
    return wrapped
48
49
50 1
class TemplateStore:
51
52 1
    def __init__(self, root):
53 1
        self.root = root
54 1
        self._items = None
55
56 1
    @load_before
57
    def read(self, key):
58 1
        try:
59 1
            model = self._items[key]
60 1
        except KeyError:
61 1
            return None
62
        else:
63 1
            return model.domain
64
65 1
    @load_before
66
    def filter(self, **_):
67 1
        templates = []
68 1
        for model in self._items.values():
69 1
            templates.append(model.domain)
70 1
        return templates
71
72 1
    def _load(self):
73 1
        self._items = {}
74 1
        for key in os.listdir(self.root):
75 1
            if key[0] not in ('.', '_'):
76 1
                model = TemplateModel(key, self.root)
77
                self._items[key] = model
78