Completed
Push — master ( aa9a3d...5e72be )
by Daniel
01:05
created

RouteManagerPlugin   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 9
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 2 1
A __init__() 0 4 1
1
from groundwork.util import gw_get
2
3
4
class RouteManagerPlugin:
5
6
    def __init__(self, plugin):
7
        self.plugin = plugin
8
        self.log = plugin.log
9
        self.app = plugin.app
10
11
    def register(self, url, methods, endpoint, context=None, name=None, description=None):
12
        return self.app.web.routes.register(url, methods, endpoint, self.plugin, context, name, description)
13
14
15
class RouteManagerApplication:
16
    def __init__(self, app):
17
        self._routes = {}
18
        self.app = app
19
20
    def register(self, url, methods, endpoint, plugin, context=None, name=None, description=None,):
21
        if context is None and self.app.web.contexts.default_context is None:
22
            raise RuntimeError("Context not give and no default context is available.")
23
24
        if context is None:
25
            context = self.app.web.contexts.default_context.name
26
27
        if name not in self._routes.keys():
28
            self._routes[name] = Route(url, methods, endpoint, context, name, description, plugin)
29
30
            for provider in self.app.web.providers.get():
31
                provider.instance.register_route()
32
33
    def get(self, name=None, plugin=None):
34
        return gw_get(self._routes, name, plugin)
35
36
37
class Route:
38
    """
39
    """
40
    def __init__(self, url, methods, endpoint, context, name, description, plugin):
41
        self.url = url
42
        self.methods = methods
43
        self.endpoint = endpoint
44
        self.context = context
45
        self.name = name
46
        self.description = description
47
        self.plugin = plugin
48
49