Completed
Pull Request — master (#177)
by Jace
03:20
created

StringList

Complexity

Total Complexity 0

Size/Duplication

Total Lines 3
Duplicated Lines 0 %

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 3
ccs 3
cts 3
cp 1
wmc 0
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 1
from yorm.types import String, List
0 ignored issues
show
Configuration introduced by
The import yorm.types 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...
5
6 1
from ..domain import Template
7
8
9 1
@yorm.attr(name=String)
10 1
@yorm.attr(link=String)
11 1
@yorm.attr(default=List.of_type(String))
12 1
@yorm.attr(aliases=List.of_type(String))
13 1
@yorm.attr(regexes=List.of_type(String))
14 1
@yorm.sync("{self.root}/{self.key}/config.yml")
15
class TemplateModel:
16
    """Persistence model for templates."""
17
18 1
    def __init__(self, key, root):
19 1
        self.key = key
20 1
        self.root = root
21 1
        self.name = ""
22 1
        self.default = []
23 1
        self.link = ""
24 1
        self.aliases = []
25 1
        self.regexes = []
26
27 1
    @property
28
    def domain(self):
29 1
        return Template(
30
            key=self.key,
31
            name=self.name,
32
            lines=self.default,
33
            aliases=self.aliases,
34
            patterns=self.regexes,
35
            link=self.link,
36
            root=self.root,
37
        )
38
39
40 1
class TemplateStore:
41
42 1
    def __init__(self, root):
43 1
        self.root = root
44 1
        self._items = {}
45 1
        for key in os.listdir(self.root):
46 1
            if key[0] not in ('.', '_'):
47 1
                model = TemplateModel(key, self.root)
48 1
                yorm.update_file(model)
49 1
                self._items[key] = model
50
51 1
    def read(self, key):
52 1
        try:
53 1
            model = self._items[key]
54 1
        except KeyError:
55 1
            return None
56
        else:
57 1
            return model.domain
58
59 1
    def filter(self, **_):
60 1
        templates = []
61 1
        for model in self._items.values():
62 1
            templates.append(model.domain)
63
        return templates
64