Passed
Pull Request — main (#14)
by Jace
57s
created

slackoff.config   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 23
dl 0
loc 33
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A Settings.activate() 0 3 1
A Settings.deactivate() 0 3 1
A Settings._update() 0 7 4
1
import log
2
from datafiles import datafile, field
3
4
5
@datafile
6
class Workspace:
7
    name: str
8
    active: bool = True
9
10
11
@datafile("~/Library/Preferences/slackoff.yml")
12
class Settings:
13
    workspaces: list[Workspace] = field(default_factory=list)
14
15
    def activate(self, name: str):
16
        log.debug(f"Marking workspace active: {name}")
17
        self._update(name, True)
18
19
    def deactivate(self, name: str):
20
        log.debug(f"Marking workspace inactive: {name}")
21
        self._update(name, False)
22
23
    def _update(self, name: str, active: bool):
24
        for workspace in self.workspaces:
25
            if workspace.name == name:
26
                workspace.active = active
27
                break
28
        else:
29
            self.workspaces.append(Workspace(name, active))
30
31
32
settings = Settings()
33